- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoding_Decoding.py
More file actions
Latest commit
47 lines (40 loc) · 1.57 KB
/
Copy pathCoding_Decoding.py
File metadata and controls
47 lines (40 loc) · 1.57 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
# Write a python program to translate a message into secret code language. Use the rules below to translate
# normal English into secret code language
# Coding:
# if the word contains atleast 3 characters, remove the first letter and append it at the end
# now append three random characters at the starting and the end
# else:
# simply reverse the string
# Decoding:
# if the word contains less than 3 characters, reverse it
# else:
# remove 3 random characters from start and end. Now remove the last letter and append it to the beginning
# Your program should ask whether you want to code or decode
importrandom
importstring
print("Welcome to coding Decoding Center")
words=input("Enter the string -\t").split()
check=int(input("Enter 1 to code, -1 to decode and 0 to quit-\t"))
wordsList= []
if (check==1):
forwordinwords:
r1=random.choice(string.ascii_uppercase) +random.choice(
string.ascii_lowercase) +random.choice(string.ascii_lowercase)
r2=random.choice(string.ascii_lowercase) +random.choice(
string.ascii_lowercase) +random.choice(string.ascii_lowercase)
if (len(word) >=3):
word=r1+word[1:] +word[0] +r2
wordsList.append(word)
else:
word=word[::-1]
wordsList.append(word)
elif (check==-1):
forwordinwords:
if (len(word) >=3):
word=word[-4:-3] +word[3:-4]
wordsList.append(word)
else:
word=word[::-1]
wordsList.append(word)
forwordinwordsList:
print(word,end=" ")