欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python——小试牛刀购物车

程序员文章站 2024-02-23 09:00:04
...

仅供自己存档,记录下学习过程
缩进就是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
相关标签: python 小试牛刀