码迷,mamicode.com
首页 > 编程语言 > 详细

python元组,列表,字典练习

时间:2017-12-26 23:11:53      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:length   iphone   ret   highlight   mac   put   play   continue   log   

#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

  

python元组,列表,字典练习

标签:length   iphone   ret   highlight   mac   put   play   continue   log   

原文地址:https://www.cnblogs.com/g177w/p/8120461.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!