Add Chapter 9 exercises
This commit is contained in:
parent
af1eb1c281
commit
13203998df
24 changed files with 1054 additions and 0 deletions
24
thinkcspy/Chapter-9-Exercises/Python-files/Problem18.py
Normal file
24
thinkcspy/Chapter-9-Exercises/Python-files/Problem18.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Runestone.Academy thinkcspy course
|
||||
# Chapter 9
|
||||
# Problem 18
|
||||
|
||||
import string
|
||||
|
||||
def encrypt(msg, code):
|
||||
alpha = string.ascii_lowercase
|
||||
newStr = ""
|
||||
pos = 0
|
||||
msg = msg.lower()
|
||||
|
||||
for char in msg:
|
||||
if char in alpha:
|
||||
pos = alpha.index(char)
|
||||
newStr += newAlpha[pos]
|
||||
else:
|
||||
newStr += char # no rules apply so keep the character
|
||||
|
||||
return newStr
|
||||
|
||||
newAlpha = "qwertyuiopasdfghjklzxcvbnm"
|
||||
|
||||
print(encrypt("Hello World!", newAlpha))
|
||||
Loading…
Reference in a new issue