• 购物车程序(待完善)


    #购物车程序

    gongzi = input("请输入您的工资:")
    if gongzi.isdigit(): #判断变量是否为正整数,包括0
    gongzi = int(gongzi)
    else:
    print("无效的工资,退出")
    exit()

    shangping = ['iphone','mac book','bike','book','pen']
    buycars = []

    print(" 目前有以下商品: ")
    for index,name in enumerate(shangping):
    print(index+1,"-", name)

    while True:
    select = input(" 请输入您想购买的商品名称,按q退出: ")
    if select in shangping:
    pass
    elif select == 'q':
    exit()
    else:
    print("对不起,您输入的商品不存在!请重新输入! ")
    continue
    if select == 'iphone':
    if gongzi - 6800 >= 0:
    gongzi = int(gongzi) - 6800
    shangping.remove("iphone")
    buycars.append("iphone")
    print(" 购买成功!已将您的商品放入购物车! ")
    print("目前余额:",end="")
    print("33[1;32m")
    print(str(gongzi))
    print("33[0m")
    else:
    print(" 对不起,您的余额不足. ")
    print("目前余额:",end="")
    print("33[1;31m")
    print(str(gongzi))
    print("33[0m")
    continue
    elif select == 'mac book':

    if gongzi - 12000 >= 0:
    gongzi -= 12000
    shangping.remove("mac book")
    buycars.append("mac book")
    print(" 购买成功!已将您的商品放入购物车! ")
    print("目前余额:",end="")
    print("33[1;32m")
    print(str(gongzi))
    print("33[0m")
    else:
    print("余额不足. ")
    print("目前余额:",end="")
    print("33[1;31m")
    print(str(gongzi))
    print("33[0m")
    continue
    elif select == 'bike':

    if gongzi - 700 >= 0:
    shangping.remove("bike")
    buycars.append("bike")
    gongzi -= 700
    print(" 购买成功!已将您的商品放入购物车! ")
    print("目前余额:",end="")
    print("33[1;32m")
    print(str(gongzi))
    print("33[0m")

    else:
    print("余额不足. ")
    print("目前余额:",end="")
    print("33[1;31m")
    print(str(gongzi))
    print("33[0m")
    elif select == 'book':

    if gongzi -80 >= 0:
    shangping.remove("book")
    buycars.append("book")
    gongzi -= 80
    print(" 购买成功!已将您的商品放入购物车! ")
    print("目前余额:",end="")
    print("33[1;32m")
    print(str(gongzi))
    print("33[0m")

    else:
    print("余额不足. ")
    print("目前余额:",end="")
    print("33[1;31m")
    print(str(gongzi))
    print("33[0m")
    elif select == 'pen':

    if gongzi - 50 >= 0:
    shangping.remove("pen")
    buycars.append("pen")
    gongzi -= 50
    print(" 购买成功!已将您的商品放入购物车! ")
    print("目前余额:",end="")
    print("33[1;32m")
    print(str(gongzi))
    print("33[0m")

    else:
    print("余额不足. ")
    print("目前余额:",end="")
    print("33[1;31m")
    print(str(gongzi))
    print("33[0m")

    print("购物车内的商品有:")
    for buycar in buycars:
    print("-",buycar)
    print("共计:"+str(len(buycars))+"件商品")
    print("余额:",gongzi," ")

  • 相关阅读:
    20175126《Java程序设计》第七周学习总结
    20175126《Java程序设计》第六周学习总结
    软工实践个人总结
    第06组 Beta版本演示
    第06组 Beta冲刺(4/5)
    第06组 Beta冲刺(5/5)
    第06组 Beta冲刺(3/5)
    第06组 Beta冲刺(2/5)
    第6组 Beta冲刺(1/5)
    第06组 Alpha事后诸葛亮
  • 原文地址:https://www.cnblogs.com/hy007x/p/7727611.html
Copyright © 2020-2023  润新知