Python——小试牛刀购物车

仅供自己存档,记录下学习过程
缩进就是python的灵魂

salary = int(input("please enter your salary:"))
float(salary)
commodity = ["iPhone:4300","iPad:2500","Kindle:1500","Book:150","weilong:10"]
count = len(commodity)
print("There have some commodity:")
for i in range(0,count):
    print(commodity[i])
while True:
    commodity_shop = input("please enter your shopping:")
    if commodity_shop == "iPhone":
        if salary > 4300:
            salary = salary-4300
            print("\033[0;32m you have %d left\033[0m" %salary)
            continue
        else:
            print("\033[0;33m warning:the left money not enough!\033[0m")
            continue
    elif commodity_shop == "iPad":
        if salary > 2500:
            salary = salary - 2500
            print("\033[0;32m you have %d left\033[0m" % salary)
            continue
        else:
            print("\033[0;33m warning:the left money not enough!\033[0m")
            continue
    elif commodity_shop == "Kindle":
        if salary > 1500:
            salary = salary - 1500
            print("\033[0;32m you have %d left\033[0m" % salary)
            continue
        else:
            print("\033[0;33m warning:the left money not enough!\033[0m")
            continue
    elif commodity_shop == "Book":
        if salary > 150:
            salary = salary - 150
            print("\033[0;32m you have %d left\033[0m" % salary)
            continue
        else:
            print("\033[0;33m warning:the left money not enough!\033[0m")
            continue
    elif commodity_shop == "weilong":
        if salary > 10:
            salary = salary - 10
            print("\033[0;32m you have %d left\033[0m" % salary)
            continue
        else:
            print("\033[0;33m warning:the left money not enough!\033[0m")
            continue
    elif commodity_shop == "Q":
        break
    else:
        print("\033[0;31m please enter the right commodity!\033[0m")
        continue
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值