2
2

More than 1 year has passed since last update.

Python3の辞書の要素を取り出す

Posted at

Python3で辞書の要素を取り出すプログラムを実装しました。

# 新規作成 2023/4/5
# 辞書の要素の

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

number = 0

while True:
    try:
        input_num = int(input(f"番号を0から{len(menus)}の間で入力してください "))
        if input_num < 0 or input_num >= len(menus):
            raise ValueError
        else:
            number = input_num
            break
    except:
        print("数字の入力が間違っています")    


# print(list(menus.items())[number])
# 
key,value = list(menus.items())[number]
print(f"{key}の意味は{value}です")
2
2
2

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