Skip to content

Commit 598cf71

Browse files
committed
Python
1 parent 16e8dec commit 598cf71

11 files changed

+290
-20
lines changed

day11(Functions).py

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ def isLesser(a, b):
2424
calculateGmean(c, d)
2525
# gmean2 = (c*d)/(c+d)
2626
# print(gmean2)
27+

day12(Arguments).py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Keyword Arguments
33
# Variable length Arguments
44
# Required Arguments
5+
56
# def Average(a,b):
67
# print("Avergae of two numbers",(a+b)/2)
78
# Average(2,5)

day13 (Lists).py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@
4747
l.extend(m) # iska mtlb l ko kholo nd ye m list ka vlaue enter kra do
4848

4949

50-
k=l+m # naya list hi bna do do lsit ko concatenate kr ke
50+
k=l+m # naya list hi bna do do lsit ko concatenate kr ke
5151
print(k)

day14(Tuples).py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#orderd coll of data items stoes multiple items single varibles
2+
# and tuples can not be chaged as lissts
3+
#not in square brackets onlly in ()
4+
tup=(4,6,7,"Vishal","danger") #class tuple h
5+
print(type(tup),tup)
6+
print(len(tup))
7+
print(tup[0])
8+
print(tup[1])
9+
print(tup[2]) # -ve indexing same comcept hota h lists me dekh chuke h
10+
print(tup[4])
11+
12+
if 3 in tup: # ye check Karega ki wo value hai ya nai tup me
13+
print("Yes")
14+
else:
15+
print("No")
16+
tup=(1) # class int h n a ki tuple isiliye (1,) ke ke karenge to retun tuple karega
17+
print(type(tup),tup)
18+
19+
tup=(1,)
20+
print(type(tup),tup)
21+
# usse ek naya tuple create ho ke print hoga ek naya tuple .
22+
tup2=tup[1:4]
23+
print(tup2)
24+
25+
26+
#OPERATUONS ON TUPLES
27+
#Manipulation on tuples
28+
countries = ("Spain", "Italy", "India", "England", "Germany")
29+
temp = list(countries)
30+
temp.append("Russia") #add item
31+
temp.pop(3) #remove item
32+
temp[2] = "Finland" #change item
33+
countries = tuple(temp)
34+
print(countries)
35+
#concatenate
36+
countries = ("Pakistan", "Afghanistan", "Bangladesh", "ShriLanka")
37+
countries2 = ("Vietnam", "India", "China")
38+
southEastAsia = countries + countries2
39+
print(southEastAsia)
40+
41+
#count
42+
tup=(1,4,6,7,9,4)
43+
res=tup.count(4)
44+
print(res)
45+
46+
#index
47+
Tuple = (0, 1, 2, 3, 2, 3, 1, 3, 2)
48+
res = Tuple.index(3)
49+
print('First occurrence of 3 is', res)

day15(strigsFormatting).py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
letter=("My name is {} and i live in {}")
2+
name="Vishal"
3+
place="BBS"
4+
print(letter.format(name,place)) # this is called string formatting
5+
#string.format(__,__)
6+
#print(string name.format(_,_))
7+
print(f"My name is {name} and i live in {place}") # f-strings dono {}iska vlaue in ho ke print hoga
8+
print(f"My name is {{name}} and i live in {{place}}") # f-strings but isme {{}} to smae as it is print ho jayega
9+
10+
11+
txt = ("For only {price:.2f} dollars!")
12+
print(txt)
13+
print(txt.format(price=89.0983438))
14+
15+
price=45.567
16+
txt = (f"For only {price:.2f} dollars!")
17+
print(txt)
18+
19+
print(f"{2*80}") #f-string
20+
print(f"{2*6}")

day16(docstrings pep8).py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def square(n):
2+
'''Takes in a number n, returns the square of n'''# ye fun def ke upar likhte h access by doc attributes
3+
print(n**2)
4+
square(5)
5+
print(square.__doc__) #docstrings print hoga
6+
7+
#PEP8 (Python enhacnment proposal)
8+
# HOW TO WRITE A CODE BEST PRACTICES
9+
import this #poem The Zen of Python Easter egggggg

day17(Recursions).py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# function ke andar usse same fuction ko call krte
2+
# factorial(7) = 7*6*5*4*3*2*1
3+
# factorial(6) = 6*5*4*3*2*1
4+
# factorial(5) = 5*4*3*2*1
5+
# factorial(4) = 4*3*2*1
6+
# factorial(0) = 1
7+
8+
9+
# factorial(n) = n * factorial(n-1)
10+
def factorial(n):
11+
if(n==0 or n==1):
12+
return 1
13+
else:
14+
return(n* factorial(n-1))
15+
print(factorial(4))
16+
print(factorial(2))
17+
print(factorial(0))
18+
# 5 * factorial(4)
19+
# 5 * 4 * factorial(3)
20+
# 5 * 4 * 3 * factorial(2)
21+
# 5 * 4 * 3 * 2 * factorial(1)
22+
# 5 * 4 * 3 * 2 * 1
23+
#FIBBONACCI SERIES
24+
# f(0) = 0
25+
# f(1) = 1
26+
# f(2) = f(1) + f(0)
27+
# f(n) = f(n-1) + f(n-2)
28+
# 0 1 1 2 3 5 8....
29+
def Fibbonacci(n):
30+
if(n==0):
31+
return 0
32+
elif(n==1):
33+
return 1
34+
else:
35+
return(Fibbonacci(n-1)+Fibbonacci(n-2))
36+
print(Fibbonacci(3))
37+
print(Fibbonacci(0))
38+
print(Fibbonacci(1))
39+
print(Fibbonacci(2))
40+
print(Fibbonacci(5))
41+
42+
43+
44+
45+
46+
47+

day9(For Loop).py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# # #FOR LOOP
2-
# # names=["Vishal","Anja","Vkash","Anvi"]
3-
# # for name in names:
4-
# # print(name)
5-
# # for i in name:
6-
# # print(i)
1+
# #FOR LOOP
2+
# names=["Vishal","Anja","Vkash","Anvi"]
3+
# for name in names:
4+
# print(name)
5+
# for i in name:
6+
# print(i)
77
# for k in range(1,9):
88
# print(k+1)
99

@@ -13,7 +13,7 @@
1313
# for k in range(2,20,2):
1414
# print(k)
1515

16-
# DO WHILE LOOP EMALUATION
16+
# #DO WHILE LOOP EMALUATION
1717
# do{
1818
# #loop body
1919
# }

ex 2 (Gm messages).py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#Good morning message
2+
3+
import time
4+
t=time.strftime('%H:%M:%S')
5+
print(t)
6+
Hour=int(time.strftime('%H'))
7+
Hour=int(input("Enter the hour:"))
8+
print(Hour)
9+
if (Hour>=0 and Hour<12):
10+
print("Good mornings python")
11+
elif(Hour>=12 and Hour<17):
12+
print("Good Afternoon sir!")
13+
elif(Hour>=17 and Hour<0):
14+
print("Good Night")
15+
16+

ex 2.py

-12
This file was deleted.

ex 3 (KBC).py

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# # Create a program capable of displaying questions to the user like KBC.
2+
# # Use List data type to store the questions and their correct answers.
3+
# # Display the final amount the person is taking home after playing the game.
4+
5+
# kbcque=['Who is the popular youtuber in India']
6+
# O=["1-Bhuvan Bham\n","2-Vishal singh\n", "3-Fukra Insaan\n","4-Triggered insaan\n"]
7+
# # L=[1,3,4,5]
8+
# # print(L.index[5])
9+
# # print(type(O))
10+
# print(O.index[2-Vishal singh])
11+
# print(kbcque)
12+
13+
# # print(O)
14+
15+
# # Res=(input("Enter the option no.:-"))
16+
# # if(Res==ans):
17+
# # print("Correct answer")
18+
# # else:
19+
# # print("Wrong answer")
20+
questions = [[ "Which language was used to create fb?", "Python", "French", "JavaScript",
21+
"Php", "None", 4],
22+
[
23+
"Which language was used to create fb?", "Python", "French", "JavaScript",
24+
"Php", "None", 4
25+
],
26+
[
27+
"Which language was used to create fb?", "Python", "French", "JavaScript",
28+
"Php", "None", 4
29+
],
30+
[
31+
"Which language was used to create fb?", "Python", "French", "JavaScript",
32+
"Php", "None", 4
33+
],
34+
[
35+
"Which language was used to create fb?", "Python", "French", "JavaScript",
36+
"Php", "None", 4
37+
],
38+
[
39+
"Which language was used to create fb?", "Python", "French", "JavaScript",
40+
"Php", "None", 4
41+
],
42+
[
43+
"Which language was used to create fb?", "Python", "French", "JavaScript",
44+
"Php", "None", 4
45+
],
46+
[
47+
"Which language was used to create fb?", "Python", "French", "JavaScript",
48+
"Php", "None", 4
49+
],
50+
[
51+
"Which language was used to create fb?", "Python", "French", "JavaScript",
52+
"Php", "None", 4
53+
],
54+
[
55+
"Which language was used to create fb?", "Python", "French", "JavaScript",
56+
"Php", "None", 4
57+
],
58+
[
59+
"Which language was used to create fb?", "Python", "French", "JavaScript",
60+
"Php", "None", 4
61+
],
62+
[
63+
"Which language was used to create fb?", "Python", "French", "JavaScript",
64+
"Php", "None", 4
65+
],
66+
[
67+
"Which language was used to create fb?", "Python", "French", "JavaScript",
68+
"Php", "None", 4
69+
],
70+
[
71+
"Which language was used to create fb?", "Python", "French", "JavaScript",
72+
"Php", "None", 4
73+
],
74+
[
75+
"Which language was used to create fb?", "Python", "French", "JavaScript",
76+
"Php", "None", 4
77+
],
78+
[
79+
"Which language was used to create fb?", "Python", "French", "JavaScript",
80+
"Php", "None", 4
81+
],
82+
[
83+
"Which language was used to create fb?", "Python", "French", "JavaScript",
84+
"Php", "None", 4
85+
],
86+
[
87+
"Which language was used to create fb?", "Python", "French", "JavaScript",
88+
"Php", "None", 4
89+
],
90+
[
91+
"Which language was used to create fb?", "Python", "French", "JavaScript",
92+
"Php", "None", 4
93+
],
94+
[
95+
"Which language was used to create fb?", "Python", "French", "JavaScript",
96+
"Php", "None", 4
97+
],
98+
[
99+
"Which language was used to create fb?", "Python", "French", "JavaScript",
100+
"Php", "None", 4
101+
],
102+
[
103+
"Which language was used to create fb?", "Python", "French", "JavaScript",
104+
"Php", "None", 4
105+
],
106+
[
107+
"Which language was used to create fb?", "Python", "French", "JavaScript",
108+
"Php", "None", 4
109+
],
110+
[
111+
"Which language was used to create fb?", "Python", "French", "JavaScript",
112+
"Php", "None", 4
113+
],
114+
]
115+
levels = [1000, 2000, 3000, 5000, 10000, 20000, 40000, 80000, 160000, 320000]
116+
money = 0
117+
for i in range(0, len(questions)):
118+
119+
question = questions[i]
120+
print(f"\n\nQuestion for Rs. {levels[i]}")
121+
print(f"a. {question[1]} b. {question[2]} ")
122+
print(f"c. {question[3]} d. {question[4]} ")
123+
reply = int(input("Enter your answer (1-4) or 0 to quit:\n" ))
124+
if (reply == 0):
125+
money = levels[i-1]
126+
break
127+
if(reply == question[-1]):
128+
print(f"Correct answer, you have won Rs. {levels[i]}")
129+
if(i == 4):
130+
money = 10000
131+
elif(i == 9):
132+
money = 320000
133+
elif(i == 14):
134+
money = 10000000
135+
else:
136+
print("Wrong answer!")
137+
break
138+
139+
print(f"Your take home money is {money}")

0 commit comments

Comments
 (0)