-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day8.py
121 lines (98 loc) · 3.37 KB
/
Day8.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import math
"""
def greet(a):
print(f"Hello {a}")
print(f"hola {a}")
print(f"Namaste {a}")
greet("Hari")"""
"""def greet_with_loc(name, loc):
print(f"Hello {name}")
print(f"You live in {loc}")
# greet_with_loc("Anthony", "Tokyo") positional argument
greet_with_loc(loc="huwai", name="James") # keyword argument"""
# Challenge no 1
"""h = int(input("Enter the height of the wall "))
w = int(input("Enter the width of the wall "))
coverage = 5
def can_used(height, width, cover):
can = (height * width) / cover
print(f"Total paint can are used is {math.ceil(can)}")
can_used(height=h, width=w, cover=coverage)"""
# Challenge no 2
'''def prime_check(num):
count = 0
for i in range(2, num // 2+1):
if num % i == 0:
count += 1
else:
continue
if count != 0:
print(f"{num} is not a prime number.")
else:
print(f"{num} is a prime number.")
number = int(input("Enter the numbr you want to check for:- "))
prime_check(number)'''
# Caesar Cipher
print("Welcome TO CAESAR CIPHER")
letters = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ")
end = True
while end:
# Taking inputs
choose = input("Type 'encode' to encode you code or type 'decode' to decode your code:- ")
if choose == 'encode':
code = input("Enter your code to encode it :- ").lower()
elif choose =='decode':
code = input("Enter your code to decode it :- ").lower()
else:
print("Wrong input, Try to run program again and enter corret input")
break
# input of spacing
code_number = int(input("Enter the number of spacing:- "))
encode = []
length_of_code = len(code)
length_of_letters = len(letters)
# converting input text in a list
for i in range(0,length_of_code):
encode.append(code[i])
result = ""
# condition for encoding
if choose == 'encode':
for j in range(0,length_of_code):
for k in range(0,length_of_letters):
if(encode[j] == letters[k]):
if(k+code_number >= 26):
encode[j] = letters[(k+code_number)-26]
# print(encode)
# print(letters)
result += encode[j]
break
else:
encode[j] = letters[k+code_number]
# print(encode)
# print(letters)
result += encode[j]
break
print(f"Your Encoded code is:- {result}")
# condition for decoding
elif choose == 'decode':
for j in range(0,length_of_code):
for k in range(0,length_of_letters):
if(encode[j] == letters[k]):
if(k+code_number < 0):
encode[j] = letters[26-k-code_number]
result += encode[j]
break
else:
encode[j] = letters[k-code_number]
result += encode[j]
break
print(f"Your Decoded code is:- {result}")
# while loop exit condition
cont = input("Do you want to continue ? Y or N:- ")
if cont == 'Y':
end = True
elif cont == 'N':
end = False
else:
print("Wrong input")
break