Update Lesson 2 Task %*f#ncA0#>? to work without libraries

This commit is contained in:
Stanislav Mykhailenko 2023-01-06 21:03:47 +02:00
parent d982e06f98
commit e2e4599c25
GPG key ID: 1E95E66A9C9D6A36

View file

@ -5,7 +5,35 @@
# Return codes:
# 0 - OK
rot13 = str.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm')
def isUppercase(chr):
if chr >= "A" and chr <= "Z":
return True
else:
return False
print(input("Enter message: ").translate(rot13))
def isLowercase(chr):
if chr >= "a" and chr <= "z":
return True
else:
return False
def isLetter(chr):
if isUppercase(chr) or isLowercase(chr):
return True
else:
return False
string = input("Enter message: ")
newstring = ''
for i in range(len(string)):
if not isLetter(string[i]):
continue
uppercase = isUppercase(string[i])
newOrd = ord(string[i]) + 13
if isLetter(chr(newOrd)) and uppercase == isUppercase(chr(newOrd)):
newstring += chr(newOrd)
else:
newstring += chr(newOrd - 26)
print(newstring)