-
Notifications
You must be signed in to change notification settings - Fork 0
/
L20Q3_Rotate.py
29 lines (26 loc) · 917 Bytes
/
L20Q3_Rotate.py
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
# Write a procedure, rotate which takes as its input a string of lower case
# letters, a-z, and spaces, and an integer n, and returns the string constructed
# by shifting each of the letters n steps, and leaving the spaces unchanged.
# Note that 'a' follows 'z'. You can use an additional procedure if you
# choose to as long as rotate returns the correct string.
# Note that n can be positive, negative or zero.
from L20Q2_ShiftNLetters import shift_n_letters
def rotate(phrase,n):
phraseout=""
for i in phrase:
if ord(i) == 32:
phraseout += " "
else:
phraseout += shift_n_letters(i,n)
return phraseout
print rotate ('sarah', 13)
#>>> 'fnenu'
print rotate('fnenu',13)
#>>> 'sarah'
print rotate('dave',5)
#>>>'ifaj'
print rotate('ifaj',-5)
#>>>'dave'
print rotate(("zw pfli tfuv nfibj tfiivtkcp pfl jyflcu "
"sv rscv kf ivru kyzj"),-17)
#>>> ???