Skip to content

Commit c2d077c

Browse files
committed
Python
1 parent 598cf71 commit c2d077c

12 files changed

+202
-0
lines changed

day18(sets).py

+15
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

+26
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

+22
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

+13
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

+22
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

+22
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

+13
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

+12
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+

day3.py day3(trail sample).py

File renamed without changes.

day4.py day4(Type).py

File renamed without changes.

ex-4 (Secret code).py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Write a python program to translate a message into secret code language.
2+
# Use the rules below to translate normal English into secret code language
3+
# Coding:
4+
# if the word contains atleast 3 characters, remove the first letter and append it at the end
5+
# now append three random characters at the starting and the end
6+
# else:
7+
# simply reverse the string
8+
# Decoding:
9+
# if the word contains less than 3 characters, reverse it
10+
# else:
11+
# remove 3 random characters from start and end. Now remove the last letter and append it to the beginning
12+
# Your program should ask whether you want to code or decode
13+
14+
#short method
15+
# def encode(word):
16+
# return word[::-1] if len(word) < 3 else "abc" + word[1:] + word[0] + "xyz"
17+
18+
# def decode(word):
19+
# return word[::-1] if len(word) < 3 else word[-4] + word[3:-4]
20+
21+
# mode = input("Choose 'encode' or 'decode': ").strip().lower()
22+
# message = input("Enter your message: ").strip()
23+
# result = ' '.join((encode if mode == "encode" else decode)(word) for word in message.split())
24+
# print("Result:", result)
25+
26+
def encode(word):
27+
if len(word) < 3:
28+
return word[::-1] # Reverse the word but -1 HELLO _1,-1 krte krte o,l,l,e,h
29+
else:
30+
return "abc" + word[1:] + word[0] + "xyz" # Modify the word
31+
32+
def decode(word):
33+
if len(word) < 3:
34+
return word[::-1] # Reverse the word
35+
else:
36+
return word[-4] + word[3:-4]
37+
38+
mode = input("Enter 'code' to encode or 'decode' to decode: ")
39+
message = input("Enter the message: ")
40+
41+
words = message.split() #convert kr dega list me "hello world"-----["hello", "world"]
42+
result = []
43+
for word in words:
44+
if mode == "encode":
45+
result.append(encode(word))
46+
elif mode == "decode":
47+
result.append(decode(word))
48+
else:
49+
print("Invalid mode. Please choose 'encode' or 'decode'.")
50+
break
51+
print("Result:", ' '.join(result)) #Joins words in the result list into a single string, with a space (' ') between each word.

ex-4(Raise error).py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# entering quit does not give error else error
2+
3+
a=input("Enter the string of 4 char:")
4+
print(a)
5+
if a != "quiz":
6+
raise ValueError("The string is invalid")

0 commit comments

Comments
 (0)