Remove .md and image files and move python files into main chapter folders
This commit is contained in:
parent
5978779a9a
commit
67806dab6a
159 changed files with 0 additions and 4562 deletions
32
thinkcspy/Chapter-9-Exercises/Problem21.py
Normal file
32
thinkcspy/Chapter-9-Exercises/Problem21.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Runestone.Academy thinkcspy course
|
||||
# Chapter 9
|
||||
# Problem 21
|
||||
|
||||
import string
|
||||
|
||||
def rot13(mess):
|
||||
# Your code here
|
||||
alpha = string.ascii_lowercase
|
||||
newStr = ""
|
||||
pos = 0
|
||||
mess = mess.lower()
|
||||
|
||||
for char in mess:
|
||||
if char in alpha:
|
||||
pos = alpha.index(char)
|
||||
|
||||
if pos <= 12:
|
||||
pos += 13
|
||||
else:
|
||||
pos = pos % 13
|
||||
|
||||
newStr += alpha[pos]
|
||||
|
||||
else:
|
||||
newStr += char # no rules apply so keep the character
|
||||
|
||||
return newStr
|
||||
|
||||
print(rot13('abcde'))
|
||||
print(rot13('nopqr'))
|
||||
print(rot13(rot13('Since rot13 is symmetric you should see this message')))
|
||||
Loading…
Reference in a new issue