Oct-27-2018, 12:20 AM
I did some tests and found your problem. The first thing I noticed was your output (which matched mine):
Since your code calls print() three times and we get three printed items, they must be all three items printed in order. So, the second item is not alphabet_shifted; instead, it's alphabet being printed on line 14. To verify that, I did this:
The deque.rotate() method is altering the deque without providing an output. So, when you call alphabet.rotate(), you're changing alphabet. Because that method does not have a return, alphabet_shifted is instantiated as None which is why the third call to print prints "None".
Quote:abcdefghijklmnopqrstuvwxyz
xyzabcdefghijklmnopqrstuvw
None
Since your code calls print() three times and we get three printed items, they must be all three items printed in order. So, the second item is not alphabet_shifted; instead, it's alphabet being printed on line 14. To verify that, I did this:
from collections import deque import string def encrypt(text,shift): ''' INPUT: text as a string and an integer for the shift value. OUTPUT: The shifted text after being run through the Caesar cipher. ''' alphabet = string.ascii_lowercase # Initializing alphabet variable print(alphabet, 1) alphabet = deque(list(alphabet)) # Turning alphabet into a list alphabet_shifted = alphabet.rotate(shift) # Assigning new variable to alphabet = ''.join(alphabet) # Re-concatenating split list print(alphabet, 2) print(alphabet_shifted) pass encrypt("Hello again", 5)Which produced:
Quote:abcdefghijklmnopqrstuvwxyz 1
vwxyzabcdefghijklmnopqrstu 2
None
The deque.rotate() method is altering the deque without providing an output. So, when you call alphabet.rotate(), you're changing alphabet. Because that method does not have a return, alphabet_shifted is instantiated as None which is why the third call to print prints "None".