2
2

More than 1 year has passed since last update.

Python3の辞書のキーから値を返すプログラム②

Last updated at Posted at 2023-04-07

以前の記事からコメントを受けてプログラムを修正しました。

# 辞書のキーから値を取り出すプログラム
#  新規作成 2023/4/5
#  修正    2023/4/6 (要素の番号ではなく要素のキーを入力する方法に変更) 
#  修正    2023/4/7  入力チェックで配列の要素を指定

menus={"pork":"豚肉","beaf":"牛肉","chicken":"鶏肉","fish":"魚肉"}

while True:
    item = input(f"{','.join(menus)}の中から1つ単語を選んでください ")
    if item in menus:
        print(menus[item])
        break
    else:
        print("入力した単語が間違っています")
   

随分シンプルな感じになりました。

2
2
0

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
2
2