作业:简易购物车

Posted on 2018-01-27 17:58  Riven-X-  阅读(92)  评论(0)    收藏  举报

有一些语法错了,所以写了好一会儿。毕竟刚学的。

 

#__author: 12051
#date: 2018/1/27

user_salary = int(input("you salare :"))

a = [ "basketball","shirt","dog","iphone","computer"]

b = [120,100,2000,6988,5499]

print("以下是可购商品列表,请输入序号选购!")

for i in range(5):

    print(i,a[i],'\t',b[i])

x = True
aa = []
bb = []
while x :

    shopping = int(input(">>>:"))
    if user_salary >= b[shopping] :

        aa.append(a[shopping])

        bb.append(b[shopping])



        user_salary = user_salary - b[shopping]
        xx = int(input("你还想继续购物吗?请输入0继续,输入1购买完毕。"))
        if xx == 1 :
            break
        continue

    xxx = int(input("你的余额低于你所选的商品!重新选购请输入0,选购完毕请输入1"))
    if xxx == 1 :
        break
print("你的余额还有:",user_salary)

print("你已购买的商品及价格",aa,bb)