2017-11-20 25 views
-1

私は、ユーザーが入力したメッセージを暗号化するためのプログラムに取り組んでいます。暗号化プロセスが終了した後、私は、プログラムが別のメッセージを暗号化するかどうかをユーザーに選択させたいと考えています。どうすればよいですか?ValueError:基数10( '')のint()のリテラルが無効ですか?

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

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 

このコードの結果、私は前に遭遇したことがないエラー。これをどうやって解決するのですか?その部分がなければならない

int(input(... 

ストア入力を文字列に

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

をチェックし、そして:

+0

これは、ユーザーが何も入力されたん意味:

は、あなたのメニューを改善する方法のヒントはこちらで回答を確認することを検討してください。ユーザーが何かを入力したことを確認すれば、それは動作します。また、tryを使用することもできます。 –

+0

https://stackoverflow.com/questions/47381636/confusion-over-invalid-syntax-caused-by-while-statementに関連する – Shadow

答えて

1

問題は、あなたが行うとき、最初の行にint型に変換しようとしているということです作業。 Creating a Menu in Python

関連する問題