zoukankan      html  css  js  c++  java
  • 购物车程序(待完善)

    #购物车程序

    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," ")

  • 相关阅读:
    Mysql表连接查询
    mysql查询语句 和 多表关联查询 以及 子查询
    MySql 模糊查询、范围查询
    Mysql外键约束设置使用方法
    python基础:re模块匹配时贪婪和非贪婪模式
    解决Ubuntu 16.04下提示boot分区空间不足的办法
    String,StringBuffer,StringBuilder的区别
    多线程模拟生产者和消费者模型
    线程同步处理
    多线程的三种实现
  • 原文地址:https://www.cnblogs.com/hy007x/p/7727611.html
Copyright © 2011-2022 走看看