Mar-20-2021, 05:27 PM
Here is my code:
My issue is that both the original text prints following "original string:" and the returned cipher. I need to format the cipher to print "after encryption:" I have tried moving the assignment of string until after text prints but no luck. For reference here is my current output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
def encrypt(string, s): cipher = '' shift = s for char in string: if char = = ' ' : cipher = cipher + char elif char.isupper(): cipher = cipher + chr (( ord (char) + shift - 65 ) % 26 + 65 ) else : cipher = cipher + chr (( ord (char) + shift - 97 ) % 26 + 97 ) return print (cipher) text = ( "If you are having problems in this class consider using office hours on Mondays or Wednesdays" ) s = int ( input ( "enter shift number: " )) print ( "original string: " , text) string = text print ( "after encryption: " , encrypt(string, s)) |
1 2 3 4 |
enter shift number: 3 original string: If you are having problems in this class consider using office hours on Mondays or Wednesdays Li brx duh kdylqj sureohpv lq wklv fodvv frqvlghu xvlqj riilfh krxuv rq Prqgdbv ru Zhgqhvgdbv after encryption: None |