Skip to content

Commit c2d077c

Browse files
committed
Python
1 parent 598cf71 commit c2d077c

12 files changed

+202
-0
lines changed

day18(sets).py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
s={2,5,2,6,2} #print in any order but not repat the value of items
2+
print(s)
3+
4+
Itemss={"Orange","Applle",9,45 }
5+
print(Itemss) # print in any order
6+
for value in Itemss:
7+
print(Itemss)
8+
9+
Vishal={}
10+
print(type(Vishal)) # this is empty dictatiory
11+
12+
#if we want an empty set then,
13+
vishal=set()
14+
print(type(vishal)) # now this is set
15+

day19(SetsMethods).py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#set methods
2+
s1={1,5,8,9}
3+
s2={4,1,2,9}
4+
# print(s1.union(s2))
5+
# s1.update(s2) #isse s1 ka value mtlb items update ho jayega
6+
# print(s1,s2)
7+
8+
print(s1.intersection(s2))
9+
print(s1.symmetric_difference(s2)) # jo vlaues common nhu h wo print hoga
10+
print(s1.difference(s2))
11+
print(s1.issuperset(s2))
12+
print(s1.issubset(s2))
13+
s1.add("Vishal")
14+
print(s1)
15+
s1.remove(8)
16+
s1.discard(2)
17+
#pop
18+
I=s1.pop() #randomly pop the elements
19+
print(I)
20+
del s1 # delte the s1
21+
22+
info = {"Carla", 19, False, 5.9}
23+
if "Carla" in info:
24+
print("Carla is present.")
25+
else:
26+
print("Carla is absent.")

day20(Dictonary).py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
dic={
2+
"Vishal": "A good boy",
3+
"Raju":"A bad boy",
4+
}
5+
print(dic["Vishal"])
6+
7+
dic={
8+
12:"Vishal",
9+
34:"Robin",
10+
879:"Anvi",'Pass':True
11+
}
12+
print(dic[879])
13+
print(dic.get(1234)) # if not found not guve error it returns none
14+
print(dic.keys()) #isse key milega
15+
print(dic.values()) # isse values milega
16+
for keys in dic.keys():
17+
print(dic.keys())
18+
19+
info = {'name':'Karan', 'age':19, 'eligible':True}
20+
print(info.items())
21+
for key, value in info.items():
22+
print(f"The value corresponding to the key {key} is {value}")

day21(Dic Methods).py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ep1 = {122: 45, 123: 89, 567: 69, 670: 69}
2+
ep2 = {222: 67, 566: 90}
3+
4+
# ep1.update(ep2) isse ep1 jo hoga update kr lega ep2 ke datta ko
5+
# # ep1.clear()
6+
# ep1.pop(122)
7+
ep1.popitem() # isse last wla item khud hat jayega no need to mention
8+
del ep1[122] # us specific value ko remobe kr dega
9+
print(ep1)
10+
11+
#print empty dic
12+
emp={}
13+
print(emp)

day22(Exception handling).py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
a=input("Enter a number :")
2+
print("multiplication of table {a} is :")
3+
try:
4+
for i in range (1,11):
5+
print(f"{int(a)}*{i}={int(a)*i}")
6+
except :
7+
print("Invalid input!")
8+
9+
10+
print("some ipmp line")
11+
print("End of the code")
12+
13+
14+
try:
15+
num = int(input("Enter an integer: "))
16+
a = [6, 3]
17+
print(a[num])
18+
except ValueError:
19+
print("Number entered is not an integer.")
20+
21+
except IndexError:
22+
print("Index Error")

day22(forloopwithelse).py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# for i in range(5):
2+
# print(i)
3+
# if i==4:
4+
# break
5+
# else: #ye tb hi use hoga mtlnb execute hoga jb loop successfully khatam hoga tb hi
6+
# print("sorry no i")
7+
8+
i=0
9+
while i<7:
10+
print(i)
11+
i=i+1
12+
13+
# if i==7:
14+
# break
15+
else: #ye tb hi use hoga mtlnb execute hoga jb loop successfully khatam hoga tb hi
16+
print("sorry no i")
17+
18+
for x in range(5):
19+
print ("iteration no {} in for loop".format(x+1))
20+
else:
21+
print ("else block in loop")
22+
print ("Out of loop")

day23(FinalKeyword).py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#FINAL keyword ke andar jo rahega wo print hoga hi hoga chahe error aaye ya nhi
2+
def fun():
3+
try:
4+
l=[1,4,6,7]
5+
i= int (input("enter the index:"))
6+
print(l[i])
7+
except:
8+
print("some error occured")
9+
finally:
10+
print("Always gives the result always print")
11+
12+
x=fun()
13+
print(x)

day24(Custom errors).py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# In python, we can /////raise//// custom errors by using the raise keyword.
2+
3+
payment=int(input("Enter the payment amount:"))
4+
if not payment>20000 and payment<5000:
5+
raise ValueError("Not a valid payment")
6+
7+
8+
a = int(input("Enter any value between 5 and 9"))
9+
10+
if(a<5 or a>9):
11+
raise ValueError("Value should be between 5 and 9")
12+
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)