-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeWord.py
More file actions
58 lines (50 loc) · 1.77 KB
/
CodeWord.py
File metadata and controls
58 lines (50 loc) · 1.77 KB
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
import random
def code():
sen = input("Enter a sentence to Code: ")
sen = sen.split()
print("Coded Sentence: ",end="")
for i in sen:
lis = list(i)
if len(lis)<=2:
lis.append(lis[0])
lis.remove(lis[0])
for i in lis:
print(i, end="")
elif len(lis)>2:
lis.append(lis[0])
lis.remove(lis[0])
alphabets = ['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']
random_letters=random.sample(alphabets,3)
lis[:0]=random_letters
lis.extend(random_letters)
for i in lis:
print(i, end="")
print(end = " ")
def deCode():
sen = input("Enter a sentence to DeCode: ")
sen = sen.split()
print("DeCoded Sentence: ",end="")
for i in sen:
lis = list(i)
if len(lis)<=2:
lis.append(lis[0])
lis.remove(lis[0])
for i in lis:
print(i, end="")
if len(lis)>2:
lis = lis[3:-3]
lis.insert(0,lis[len(lis)-1])
lis.pop()
for i in lis:
print(i,end="")
print(end=" ")
print("\t\t\t..............Codeword Converter...............")
print('''Choose corrosponding Number to Code or DeCode:
1. Code
2. Decode''')
a = int(input("Enter Option: "))
match a:
case 1:
code()
case 2:
deCode()