File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ def to_encrypt (text , delta ):
2+ s = ''
3+ for i in text :
4+ if ord (i )== 32 :
5+ s += chr (32 )
6+ elif ord (i ) + delta > 122 :
7+ s = s + chr (ord ('a' )+ ord (i )+ delta - ord ('z' )- 1 )
8+ elif ord (i ) + delta < 97 :
9+ s = s + chr (ord ('z' )- ord ('a' )+ ord (i )+ delta + 1 )
10+ else :
11+ s = s + chr (ord (i )+ delta )
12+ return s
13+ if __name__ == '__main__' :
14+ print ("Example:" )
15+ print (to_encrypt ('abc' , 10 ))
16+
17+ #These "asserts" using only for self-checking and not necessary for auto-testing
18+ assert to_encrypt ("a b c" , 3 ) == "d e f"
19+ assert to_encrypt ("a b c" , - 3 ) == "x y z"
20+ assert to_encrypt ("simple text" , 16 ) == "iycfbu junj"
21+ assert to_encrypt ("important text" , 10 ) == "swzybdkxd dohd"
22+ assert to_encrypt ("state secret" , - 13 ) == "fgngr frperg"
23+ print ("Coding complete? Click 'Check' to earn cool rewards!" )
You can’t perform that action at this time.
0 commit comments