-1

I have been working on a program that is meant to encrypt messages inputted by the user. After the encryption process is finished, I would like the program to prompt the user to choose whether they want to encrypt another message or not.

    option2 = int(input('Would you like to encrypt another message? (Yes = 1 and No = 2)'))
    while option2 not in [1, 2]:

        print 'Please type 1 or 2.'
        option2 = int(raw_input())
    while True:
        option2 = int(raw_input())
        if option2 == 1:
            option1 = int(input('Which encryption method would you like to use? 1 = Across (NOPQ ...) and 2 = Backwards (ZYXW ...)'))
    while True:
        option2 = int(raw_input())
        if option2 == 2:
            break

This code results in

"ValueError: invalid literal for int() with base 10: ''"

an error I have never before encountered. How do I fix this?

Mariofan717
  • 57
  • 1
  • 1
  • 6
  • This means the user typed nothing. If you make sure the user types something, it will work. You could also use a try and except – whackamadoodle3000 Nov 20 '17 at 01:38
  • Related to https://stackoverflow.com/questions/47381636/confusion-over-invalid-syntax-caused-by-while-statement – Shadow Nov 20 '17 at 01:45

1 Answers1

1

The issue is that you are trying to convert to int in the first line, when you do:

int(input(...

Store input in a string, check for

 option2 not in ['1', '2']

And that part should work.

Consider checking the answers in here for tips on how to improve your menu: Creating a Menu in Python

Pablo Oliva
  • 334
  • 3
  • 12