zoukankan      html  css  js  c++  java
  • 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
    

      

  • 相关阅读:
    终结篇:MyBatis原理深入解析(二)
    Centos7 安装clamav杀毒
    jenkins 自动化部署
    docker 安装redis
    linux CentOS7 安装字体库-转
    docker 安装jenkins
    linux 下安装docker
    linux 下安装redis
    linux 下mongo 基础配置
    Linux下MongoDB安装和配置详解
  • 原文地址:https://www.cnblogs.com/g177w/p/8120461.html
Copyright © 2011-2022 走看看