1
1

More than 3 years have passed since last update.

[Python]お買い物プログラム

Last updated at Posted at 2020-11-22

Pythonでお買い物プログラムを作る

items = {'apple': 100, 'banana': 200, 'orange': 400}
money = 1000
for item_name in items:
    print('--------------------------------------------------')
    print('財布には' + str(money) + '円入っています')

    print(item_name + 'は1個' + str(items[item_name]) + '円です')

    input_count = input('購入する' + item_name + 'の個数を入力してください:')
    print('購入する' + item_name + 'の個数は' + input_count + '個です')
    count = int(input_count)
    total_price = items[item_name] * count
    print('支払い金額は' + str(total_price) + '円です')

    if money >= total_price:            
        print(item_name + 'を' + input_count + '個買いました')            
        money -= total_price            
    else:            
        print('お金が足りません')            
        print(item_name + 'を買えませんでした')

以上

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