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")
  • 相关阅读:
    点击鼠标获得坐标位置
    广告的字一个一个的显示出来
    纯css实现下拉菜单的效果
    用css3写出的倒三角形
    MySQL(三)
    Navicat之MySQL连接(二)
    MySQL 的安装与使用(一)
    Servlet(二)
    Servlet(一)
    Linux常用命令大全
  • 原文地址:https://www.cnblogs.com/hinimix/p/7772425.html
Copyright © 2011-2022 走看看