I dont know why my caesar code wont work

This is the place for queries that don't fit in any of the other categories.

I dont know why my caesar code wont work

Postby MHills » Sat Sep 24, 2016 4:52 pm

Code: Select all
## Menu
print('Main Menu')
print()
print('e: Encrypt')
print('d: Decrypt')
print('q: Quit')
print()

valid = False

while valid == False:
    choice = input('Enter Option')

    if choice in 'E D Q e d q'.split():
        valid = True
        if choice == 'e E':
            message = input('Enter message: ')
            print()

            key = int(input('Enter Key: '))

            translated = ''
            for i in message:
                asciiVal = ord(i)
                letterVal = asciiVal - 64
                letterVal = letterVal + key

            if letterVal > 26:

                letterVal = letterVal - 26

                asciiVal = letterVal + 64
            j = chr(asciiVal)

            translated = translated + j

            print(translated)

        elif choice == 'd D':
              message = input('Enter message: ')
              print()
              key = int(input('Enter Key: '))

              translated = ''
              for i in message:
                  asciiVal = ord(i)
                  letterVal = letterVal - key
                  if letterVal < 1:
                      letterVal = letterVal + 26

                  asciiVal = letterVal - 64
                  j = chr(asciiVal)
                  translated = translated + j
                  print(translated)
Last edited by Yoriz on Sat Sep 24, 2016 5:12 pm, edited 1 time in total.
Reason: First post lock. Added code tags.
MHills
 
Posts: 1
Joined: Sat Sep 24, 2016 4:50 pm

Re: I dont know why my caesar code wont work

Postby DrakeMagi » Sun Sep 25, 2016 1:30 am

They would have to type that exactly.
Code: Select all
if choice == 'e E'

option 1
Code: Select all
if choice.lower() == 'e'

option 2
Code: Select all
if choice == 'e' or choice == 'E'

option 3
Code: Select all
if choice in 'eE'
Linux: won't find windows here.
Linux: the choice of a GNU generation.
https://github.com/DrakeMagi
DrakeMagi
 
Posts: 112
Joined: Sun May 12, 2013 8:36 pm


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 9 guests