zoukankan      html  css  js  c++  java
  • 05: 整合前面学习的基础知识,写一个简单的购物车小程序

    #程序:购物车程序
    #需求:
    # 1 启动程序后,让用户输入工资,然后打印商品列表
    # 2 允许用户根据商品编号购买商品
    # 3 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒
    # 4 可随时退出,退出时,打印已购买商品和余额
    =========================================================================================================================
    代码一定要自己写,看完了教程怎么写的,然后闭着眼睛按自己思路写。
    路漫漫其修远啊,第一次写居然花了1个半小时。还有很长的路要走。。。。。。。


    shopping_list = [
    ('Iphone',1000),
    ('shucai',300),
    ('pen',600),
    ('water',700),
    ('momday',500)
    ]
    goumai_list = []
    money = input("请输入你的金额:")

    if money.isdigit(): #判断输入的是整数
    money = int(money)
    while True:
    for index,ltem in enumerate(shopping_list):
    print(index,ltem)
    you_qs=input("请选择要购买的商品:")
    if you_qs.isdigit(): #判断输入的是整数
    you_qs=int(you_qs)
    if you_qs < len(shopping_list) and you_qs >= 0:
    tmp_goumai=shopping_list[you_qs]
    if tmp_goumai[1] <= money: # 金额足够
    goumai_list.append(tmp_goumai)
    money -= tmp_goumai[1]
    print("33[31;1m当前金额还剩余%s33[0m"%money)
    else:
    print("33[41;1m你的余额只剩[%s]啦,还买个毛线,输入q退出33[0m" % money)
    else:
    print("商品不存在,请重新选择,退出请输入: q ")
    elif you_qs == "q": # 退出
    print("======退出购买:程序结束=====")
    print("当前已购买的物品清单:")
    for list in goumai_list:
    print(list)
    print("剩余金额 %s" %money)
    exit()
    else:
    print("选择错误----请重新选择---退出请输入: q")
    else:
    print("请输入正确的工资比如 1000:",money)


  • 相关阅读:
    oracle数据库 表空间不够的处理方式
    Xlib: connection to ":0.0" refused by server错误
    ORA16038的解决
    ORA16014: log string sequence# string not archive
    DBCA创建oracle时提示 file etc oratab is not accessible
    ORA01078 & LRM00109
    配置oracle10g oem中的主机身份证明的方法
    ORA12526: TNS:listener: all appropriate instances
    windows下卸载oracle
    RMAN03009,ORA_19809,ORA_19804错误解决
  • 原文地址:https://www.cnblogs.com/jim-xu/p/11697182.html
Copyright © 2011-2022 走看看