my code from strap to all updated

 


"""
print("Bhushan")
print("my name is \n Bhushann")
print("hello world")

print('''Twinkle-Twinkle Little Star'''
         '''hello wonder what youy are''')



from playsound import playsound
playsound('E:\\python notes code with harry\\1. Chapter 1\\play.mp3')

import os
print(os.listdir())

# author:bhushan
# book: code with harry
# name : python learning

a = 'Bhushan'
b = 345
c = 11.15
# printing the variables and printing their types as well
print(a,type(a))
print(b,type(b))
print(c,type(c))
print(a)
print(b)
print(c)

print('table of 2 is below guys:\n')
i = 0
a = 1
while i<10:
    print(a*2)
    a = a+1
    i = i+1

# operators
a = 3
b = 4
#Arithgmatic operators
print("the value of 3+4 is", 3+4)
print("the value of 3+4 is", 3-4)
print("the value of 3+4 is", 3*4)
print("the value of 3+4 is", 3/4)

#Assignment operators
a = 3
a += 4
a *= 4
a /= 4
print(a)

#Comparison operators
z : (14==7)
print(z)
a = 2
b = 4
print(a == b)



# logical operators

bool1 = True
bool2 =False
print("the value of bol1 and bol2 is", (bool1 and bool2))
print("the value of bol1 and bol2 is",(bool1 or bool2))
print("the value of bol1 and bol2 is",(not bool1))
# typecasting
a = input('enter your name')
print(a)
print(type(a))

# a = 20
# b = 30
# print("sum of a and b is", a + b)
a =  input("enter a ")
b = input("enter b")
a = int(a)
b = int(b)
avg = (a+b)/2
print("the average of a and b is", avg)

a = input("enter a")
a = int(a)
sqr = (a*a)
print("sqr of a is",sqr)
name = "bhushan bhau"
# print(name[0:6:2])
d = name[1:4:2]
print(d)
print(len(name))
print(name.endswith("n"))
print(name.capitalize())
print(name.find("bhau"))
print(name.replace("bhushan","BhushanSeth"))

story = "bhushan dhamankar \n is a good boy \t \\pata nahi bhai"
print(story)
pr_01
a = input("enter your name")
print("good afternoon," + a)
# pr_02
letter = '''Dear <|NAME|>,
greetings from ABC house. i am happy to tell your selection
you are selected!
have a great day!
date: <|DATE|>
'''
name = input("enter your name\n")
date = input("enter your date\n")
letter = letter.replace("<|NAME|>", name)
letter = letter.replace("<|DATE|>", date)
print(letter)
# pr_03 to find double spaces
st = "This is a string with double   spaces"
doubleSpace = st.find("  ")
print(doubleSpace)
# pr_03 to find double spaces and replace it with single one
st = "This is a string with double   spaces"
st = st.replace("  "," ")
print(st)
pr_05 letter
letter = "dear bhushan, this python course is nice!, thanks!" 
print(letter)
formatted_letter = "dear bhushan, \n this python course is nice!\n\t, thanks!" 
print(formatted_letter)
Lists and touples

a = [1,2,3,4,5,6,7,8,9,0,10]
a[0] = 95
print(a[0])
print(a[4])
#list slicing
friends = ["bhushan","bhu","bh","bhush","bss n bhau"]
print(friends[0:4])
print(friends[-4:3])

l1 = [1,2,3,4,94,6,75,8,9,0,10]
print(l1)
l1_sorted = l1.sort() #used to sort the list to acending 
print(l1)
l1.reverse()
print(l1)
l1.append(4545) #adds to the end of list
print(l1)
l1.insert(0,544) #inserts to specific position
print(l1)
l1.pop(2)
print(l1)
l1.remove(544)
print(l1)

#touples
t = (1, 2, 4, 5)
print(t[0])
print(t)
t1 = (1,) #touple with simple eleement (wrong way to enter is t1 = (1)without comma
print(t1)

t = (1, 2, 4, 1, 1, 11, 1, 5)
print(t.count(1))
print(t.index(4))

f1 = input("entyer the fruit no 1: ")
f2 = input("entyer the fruit no 2: ")
f3 = input("entyer the fruit no 3: ")
f4 = input("entyer the fruit no 4: ")
f5 = input("entyer the fruit no 5: ")
f6 = input("entyer the fruit no 6: ")
f7 = input("entyer the fruit no 7: ")
myFruitslits = [f1, f2, f3, f4, f5, f6, f7]
print(myFruitslits)

m1 = input("enter the marks of students no 1: ")
m2 = input("enter the marks of students no 2: ")
m3 = input("enter the marks of students no 3: ")
m4 = input("enter the marks of students no 4: ")
m5 = input("enter the marks of students no 5: ")
m6 = input("enter the marks of students no 6: ")
m7 = input("enter the marks of students no 7: ")
Markslist = [m1, m2, m3, m4, m5, m6, m7]
print(Markslist)

a = [2, 4, 6, 8]
print(a[0] + a[1] + a[2] + a[3])
print(sum(a))

a = (7, 0, 8, 0, 0, 9)
print(a.count(0))

d1 = {
    "fast" : "in a quick manner",
    "buy" : "purchase",
    "slow" : "in a slower manner",
    "anotherdict":{'harry': 'bhushan'}
    }
print(d1["slow"])
print(d1['anotherdict'])
#dictionary methods
print(list(d1.keys())) #prints the keys of the dictionaries
print(list(d1.values()))  #prints the values of the keys of the dictionaries
print(d1.items()) #prints the full list(key & items) of our dictionary
newd1 = {
    "bhushan" : "Dhamankar"
}
d1.update(newd1)
print(d1)
print(d1.get("bhushan")) #prints value of bhushan from the list i.e. dhamankar
print(d1.get(["Bhushan"]) # also prints using sqquare brakets prints value of bhushan from the list i.e. dhamankar

print(myDict.get("bhushan2")) # Returns None as harry2 is not present in the dictionary
print(myDict["bhushan2"]) # throws an error as harry2 is not present in the dictionary
 

a = { 1, 2, 1, 45, 566}
print(type(a))
print(a) #writes 1 only one times becxause it dows not allows repetatiion
b = {}
print(type(b)) #this will create an empty dict. and not empty set  
#an empty set can be created by using the following syntax
c = set()
print(type(c))
c.add(455)
c.add(1080)
print(c)
#you cannot add list as well as dictionary in the set but you can add touple in it
c.add((1, 4, 56456, 98))
print(c)

#dictionary
#write a code to find the hindi dictionary
d1 = {
    "beta" : "son",
    "behen":"sister",
    "pankha": "fan",
    "vastu" : "items",
    "khilona" : "toys"
}
print("options are", d1.keys())
a = input("enter the hindi word\n")
print("remaining of yoour word is:", d1[a])
# Below line will not throw an error if the key is not present in the dictionary
print("The meaning of your word is:", d1.get(a))

#get 8 numbers from ther users and print the 8 unique words for the users

n1 = int(input("enter nuymber1: "))
n2 = int(input("enter nuymber2: "))
n3 = int(input("enter nuymber3: "))
n4 = int(input("enter nuymber4: "))
n5 = int(input("enter nuymber5: "))
n6 = int(input("enter nuymber6: "))
n7 = int(input("enter nuymber7: "))
n8 = int(input("enter nuymber8: "))
s = {n1, n2, n3,n4, n5, n6, n7, n8}
print(s)

#can we hasve a set with 10 string float and int as well 
s = {10, "10.1", 10.1}
print(s)

#whaty will be the length of the folowing set
s = set()
s.add(20)
s.add(20.0) #20 andf 20.0 will be counted once as a 20 only
s.add("20")
print(s.__len__())

favlan = {}
a = input("enter your fav lang. bhushan:\n")
b = input("enter your fav lang. roshan:\n")
c = input("enter your fav lang. rakesh:\n")
d = input("enter your fav lang. ritesh:\n")
e = input("enter your fav lang. jitesh:\n")
f = input("enter your fav lang. pravin:\n")
g = input("enter your fav lang. DjSagar:\n")
favlan['bhushan'] = a
favlan['roshan'] = b
favlan['rakesh'] = c
favlan['ritesh'] = d
favlan['jitesh'] = e
favlan['pravin'] = f
favlan['DjSagar'] = g
print(favlan)

#if else statement
a = int(input("enterf value of a"))
if(a>44):
    print("the value of a is greater ")
elif(a==44):
    print("the value of a is equal to 44")
else:
    print("a is lesser tha 45")

print("done")

#take age from the user and print wheter it is greater than 18 or not
a = int(input("enter your age"))
if(a>=18):
    print("greater")
else:
    print("lesser")

#relational operators
a = int(input("enter your age"))
if(a==18 or a>18):
    print("equals to 18 or greater")
else:
    print("lesser")

a = [45, 56, 6]
print(445 in a) #prints true if 445 is in a but in this situation it prints FAlse


#to find the greatest among the 4 numbers entered by the users
a = int(input("enter number 1: "))
b = int(input("enter number 2: "))
c = int(input("enter number 3: "))
d = int(input("enter number 4: "))
if(a>d):
    f1 = a   
else:
    f1 = d
if(b>c):
    f2 = b
else:
    f2 = c
if(f1>f2):
    print(str(f1), "is greatest")
else:
    print(str(f2), "is greatest")


sub1 = int(input("enter the 1st sub marks\n"))
sub2 = int(input("enter the 2nd sub marks\n"))
sub3 = int(input("enter the 3rt sub marks\n"))
if(sub1 <33 or sub2 <33 or sub3<33):
    print("you are fail because you have less than 33% in any subject")
if(sub1+sub2+sub3)/3 <40:
  print("you are fail due to total percent or less than 40")  
else:
    print("congratulations \n you passed the exam")


#spam detector
text = input("enter the text\n \b")

if("make a lot of money" in text):
    spam = True
elif("buy now" in text):
    spam = True
elif("click this" in text):
    spam = True
elif("subscribe this" in text):
    spam = True
else:
    spam = False
if(spam):
     print("this text is spam")
else:
    print("this text is not spam")


#write a program in which you can finbd the length of name of user less than 10 character
name = str(input("enter your name brother\n"))
if(len(name)<=5):
    print("your name have less tham 10 character")
else:
    print("your name have more  characters")
print(len(name))

#write a program which finds out whether a given nameris present  in a list or not
d1 = ["bhushan", 'akash',' acp', 'kartik']
name = input("enter your name to check\n")

if name in d1:
    print("your name is  in the list")
else:
    print("your name is not present in the list")

#convert the marks of the user to the grading system
m1 = int(input("enter your marks brother\n"))
if  m1>89 and m1<101 :
    print("your grade is EX")
elif m1>79 and m1<91 :
    print("your grade is A")
elif m1>69 and m1<81:
    print("your grade is B")
elif m1>59 and m1<71 :
    print("your grade is C")
elif m1>49 and m1<61 :
    print("your grade is D")
elif m1>1 and m1<50 :
    print("your grade is F")
else:
    print("enter valid marks")

#loops
a = 1
while a<10 :
    print("bhushan\t" + str(a))
    a = a + 1

#print 0 to 50
i = 1
while i <=50:
    print(i)
    i = i+1

#print the content of the list using  while loop
i = 0 
fruit = ['apple','banana','guawa','watermelon','mangoes']
while i<len(fruit):
    print(fruit[i])
    i = i+1

#FOR Loop

i = 0
l = [1, 7, 8]
for items in l :
    print(items)

for i in range(1, 8):
    print(i)

i=0
for i in range(1,10):
    print(i)
else:
    print("this is inside else of for")
    

#break statement
i=0
for i in range(10):
    print(i)
    if i==5:
        break
else:
    print("this is inside else of for") #this dosent work if the condition is satisfied and breaked

#continue statement
i=2
for i in range(10):
    print(i)
    if i == 5:
        continue
else:
    print("this is inside else of for") #this  work if the condition is satisfied and continued

#ch7 practice set
#to make a multiplication table using for loop
num = int(input("enter the number"))
for i in range (1,11):
    i == i+1
    # print(str(num) + "X" + str(i) + "=" + str(i*num))  
    print(f"{num}X{i}={i*num}")
    # f is used as a s string here we dont have to wirte the string all the times

# write a prog. to gree the names which starts with s
list = ["bhushan","soha", "ram", "sahil"]
for name in list:
    if name.startswith("s"):
        print("hello " + name)

#to make a multiplication table using while loop
i = int(input("enter the number\n"))
j = 0
while j <10:
    j = j+1
    print(f"{i}X{j}={i*j}")
    

#to find whether the given number is prime or not
i = int(input("enter the number:"))
prime = True
for j in range(2, i):
    if(i%j ==0):
        prime = False
        break
if prime:
    print("this number is prime")
else:
    print("this is not prime number")

#write a program to find the sum of first n natural number using while loop 



#write a prigram to calculate the factorial of a givenm number using for loop
inp = int(input("enter the number: "))
factorial = 1

for i in range(1, inp+1):
    factorial = factorial * i
print(f"the factorial of the {inp} is{factorial}")


# print the star pattern (simpled) 
# *
# **
# ***
# *****
n = 5
for i in range(5):
    print("*" * (i+1))

# print the star pattern (spaced)
#        *
#       ***
#      *****
n = 3
for i in range(3):
    print(" " * (n-i-1), end=" ")
    print("*" * (2*i+1), end=" ")
    print(" " * (n-i-1))


#to make a multiplication table in reverse order
num = int(input("enter the number"))
i = 10
for i in range (10):
    i = i-10
    # print(str(num) + "X" + str(i) + "=" + str(i*num))  
    l1 = [f"{num}X{i}={i*num}"]
    l1.reverse
    print(l1)

# functions
def percent(marks):
    p = ((marks[0]+marks[1]+marks[3])/400)*100
    return p 
marks1 = [10, 50, 66, 47]
percentage = percent(marks1)

marks2 = [11,14,54,66]
percentage2 = percent(marks2)
print(percentage, percentage2)


#quiz to greet the name and call it
def greet(name):
    print("good morning, " + name)

greet("bhushan")

#types of function
#built in function and user defined functions
def sum1(num1, num2):
    return num1 + num2
s= sum1(45,52)
print(s)


# default parameter value this is used when called but not given any inputs given below
def greet(name = "stranger"):
    print("good morning, " + name)

greet("bhushan")
greet()

#recursion
# n! = 1 * 2 * 3 * 4 ....*n
n = 4
product = 1
for i in range(n):
    product = product * (i+1) 
print(product)

def factorial_iter(n):
    product = 1
    for i in range(n):
        product = product * (i+1) 
    return  n * factorial_recursive(n-1)

def factorial_recursive(n):
    if n == 1 or n  ==0:
        return 1
    return n * factorial_recursive(n-1)
f = factorial_recursive(5)
print(f)
"""

Comments