products = [("万年筆", 9800), ("ボールペン", 200), ("鉛筆", 40)]
for i, (item, price) in enumerate(products):
print(f"{i}: {item} {price}円")
while True:
try:
n = int(input("商品のインデックス?"))
item, price = products[n]
print(f"{item}は{price}円です")
except ValueError as e:
print(f"ValueErrorが起きました\n{type(e)} {e.args[0]}")
except Exception as e:
print(f"Exceptionが発生しました\n{type(e)} {e.args[0]}")
print("おわり")
# プログラム10-13(例外の階層とハンドラの選択)