zoukankan      html  css  js  c++  java
  • 练习

    list练习

    1,启动后,让用户输入工资,打印商品列表
    2,允许用户根据商品编号购买商品
    3,用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒
    4,可随时退出,退出时,打印已购买的商品和余额

    #!/usr/bin/env python3
    # -*- coding:utf-8 -*-
    # -*- Author:Hinimix -*-
    
    goods_list = [["yerongqiu", 20], ["iphone", 5000], ["muzhibing", 30], ["ipad", 2500], ["meng", 10000]]
    
    salary = int(input("enter your salary"))
    select_list = []
    
    while True:
        print("goods are below")
        for good in goods_list:
            print(good)
        selection = input("select your goods")
        for tmp in range(0,len(goods_list)):
            if goods_list[tmp][0] == selection:
                select_list.append(goods_list[tmp])
                salary -= goods_list[tmp][1]
                break
        else:
            print("no this good")
        if salary < 0:
            select_list.pop()
            print("you had bought %s" % select_list)
            exit()
        op = input("press c to continue, q to quit")
        if op == 'q':
            print("you had bought %s" % select_list)
            print("money left %d" % salary)
            break
        elif op == 'c':
            continue
        else:
            print("wrong input")
  • 相关阅读:
    函数与宏定义实验报告
    C语言作业3
    循环结构课后反思
    C语言作业2
    C程序设计实验报告
    百分制成绩五级分制输出--二次作业
    第九章 结构体与共用体
    第八章 指针实验
    第七章 数组实验
    第六章 函数和宏定义实验(2)
  • 原文地址:https://www.cnblogs.com/hinimix/p/7772425.html
Copyright © 2011-2022 走看看