• python元组,列表,字典练习


    #coding = utf-8
    
    goods_data = (["iphone7",8000],["mac pro",12000],["bike",1000])
    buyed_goods =[]
    def display_menu():
    
        mes = '''
        ******购物商城系统******
            1.%s    %d
            2.%s    %d
            3.%s    %d
            4.退出系统
        ************************
        '''%(goods_data[0][0],goods_data[0][1],goods_data[1][0],goods_data[1][1],goods_data[2][0],goods_data[2][1])
        print(mes)
    def showbought(buyed_goods):
        length = len(buyed_goods)
        mes = '''
        ---购物清单---
        '''
        print(mes)
        for i in(buyed_goods):
            print(i)
    def toselect():
        display_menu()
        selected = int(input("请选择:"))
        return selected
    yue = int(input("输入金额:"))
    while True:
        se =toselect()
        if(se == 1 and yue >= goods_data[0][1] ):
            buyed_goods.append([goods_data[0][0],goods_data[0][1]])
            yue -= goods_data[0][1]
            print("购买商品%s成功,花费%d RMB,余额为:%d" % (goods_data[0][0], goods_data[0][1],yue))
            continue
    
        if(se ==2 and yue >= goods_data[1][1]):
            buyed_goods.append([goods_data[1][0], goods_data[1][1]])
            yue -= goods_data[1][1]
            print("购买商品%s成功,花费%d RMB,余额为:%d" % (goods_data[1][0], goods_data[1][1], yue))
            continue
    
        if(se ==3 and yue >= goods_data[2][1]):
            buyed_goods.append([goods_data[2][0], goods_data[2][1]])
            yue -= goods_data[2][1]
            print("购买商品%s成功,花费%d RMB,余额为:%d" % (goods_data[2][0], goods_data[2][1],yue))
            continue
        else:
            print("余额不足!!!")
            showbought(buyed_goods)
            break
    

      

  • 相关阅读:
    懒加载数据,在取出数据时容易出的bug....
    小程序申请及小程序发布
    SSL证书申请及安装
    iview modal 覆盖问题
    取消div独占一行的特性
    GPS坐标互转:WGS-84(GPS)、GCJ-02(Google地图)、BD-09(百度地图)、(百度坐标转谷歌坐标)
    工厂方法模式
    STS创建SpringBoot项目
    snmp协议学习记录
    操作系统命令学习记录
  • 原文地址:https://www.cnblogs.com/g177w/p/8120461.html
Copyright © 2020-2023  润新知