sj_dde

导航

 

也许我真的有程序员天赋

 

# __author:"AMARA"
# date:2021/9/5 14:30

s = int(input('your salary>>'))
print(''' 
1.iphone 12 6500元
2.switch 2200元
3.coffee 35元
4.book 60元
5.TV 12000元   
6.quit
''' ) #购物列表
shop_list = [6500,2200,35,60,12000] #价格列表
shop_list1 = ['iphone 12 6500元','switch 2200元','coffee 35元','book 60元','TV 12000元'] #商品列表

buy_list = ['your shopping list'] #购物清单
i=1
while i > 0 :
    buy = input('the commodity number>>') #输入要购买的序号
    if int(buy) < 6:
        price = int(shop_list[int(buy) - 1]) #在价格列表中提取
        if s - price < 0: #余额不足
            print("your salary is not enough")
            continue
        else: #余额足
            s=s-price
            b=shop_list1[int(buy)-1] #在商品列表中提取
            buy_list.append(b) #合并成新的购物清单
            print(buy_list)
            print("your surplus is",s) #打印余额
    i += 1
    if int(buy) == 6: #退出程序
        print('thank you')
        print(buy_list)
        break
    else: #输入错误
        print('please input again')

 

posted on 2021-09-05 18:35  sj_dde  阅读(100)  评论(0)    收藏  举报