LoginSignup
0
0

More than 3 years have passed since last update.

inputで0から3以外を入力した時に再入力へ促したい

Posted at

この内容で実行しようと思っています。
inputで選択できるのは0-3です。
私はこのコードに

もし0.1.2.3以外を入力したら

0-3の数字を入力してください

と出力してもう一度数字を入力できるようにしたいです。
できないなりに
if inputNum != 0 and inputNum != 1 and inputNum != 2 and inputNum != 3:
print("0-3の数字を入力してください")
とか、isdigitとか例外処理とかやってみたけどpritnは表示されてももう一度数字を入力することはできません。
0-3の入力に「あ」とか「*」とか、「11」なんでも0-3以外は駄目なようにしたい。

dic = {}

while True:
print("[0]新しい英単語を追加\n[1]英単語を検索する\n[2]登録単語を表示する\n[3]アプリを閉じる")
inputNum = input()

    if int(inputNum) == 0:
        print("単語の意味(日本語)を入力してください。")
        word1 = input()
        print("英単語(単語)を入力してください。")
        word2 = input()

        dic[word1] = word2

        print("追加しました")
        print(dic)
    elif int(inputNum)== 1:
        print("検索したい(単語)の日本語を入力してください。")
        word = input()
        print(dic[word])
    elif int(inputNum) == 2:
        print("登録英単語帳データ:")
        for k, v in dic. items():
            print("英単語の意味", k)
            print("英単語", v)
    elif int(inputNum)== 3:
        print("終了します")
        break

でもできない;;

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0