-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhomework_after_lesson7.py
More file actions
42 lines (36 loc) · 940 Bytes
/
homework_after_lesson7.py
File metadata and controls
42 lines (36 loc) · 940 Bytes
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
file = open("decfile.txt", "r+")
word = str(file.read()).lower()
choice = input("encode or decode? ").lower()
def encode(word):
encoword = ""
m = 0
alphabet = "abcdefghijklmnopqrstuvwxyz"
falphabet = "cdefghijklmnopqrstuvwxyzabв"
for x in word:
m = alphabet.find(x)
if x not in alphabet:
encoword += " "
else:
encoword += falphabet[m]
return encoword
def decode(encoword):
word = ""
m = 0
alphabet = "abcdefghijklmnopqrstuvwxyz"
falphabet = "cdefghijklmnopqrstuvwxzab"
for x in encoword:
m = falphabet.find(x)
if x not in falphabet:
word += " "
else:
word += alphabet[m]
return word
if choice == "encode":
encoword = encode(word)
print(encoword)
file.write("\n" + encoword)
elif choice == "decode":
encoword = word
word = ""
word = decode(encoword)
print(word)