day5作业:购物车(1)

输入工资金额.展示商品,选择购买商品

# -*- coding: utf-8 -*-
# @Author: oppend
# @Date:   2017-07-26 19:07:32
# @Last Modified by:   oppend
# @Last Modified time: 2017-07-26 22:58:37
menu = '''
    ----------menu----------
    [1]bike            1500
    [2]tea             80
    [3]computer        3800
    [4]car             80000
    ------------------------
'''
goodsname = ['bike','tea','computer','car']
goodsprice = [1500,80,3800,80000]
print(menu)
salary = int(input('你的工资为:'))
while True:
    choicenum = input('选择商品序号:')
    choiceshop = []
    amount = 0
    if not choicenum.isdigit():
        if choicenum == 'quit':
            break
        else:
            print('请输入商品序号!')
            continue
    else: 
        index_num = int(choicenum)-1
        if goodsprice[index_num] <= salary:
            choiceshop.append(goodsname[index_num])
            amount += goodsprice[index_num]
            salary -= amount
            print('您购买了{},剩余金额{}元'.format(goodsname[index_num],salary))
            chonice_continue = input('是否继续购物[Y/N]:')
            if chonice_continue  == 'N':
                break
        else:
            print('余额不足,您还有{}元'.format(salary))
            break

你可能感兴趣的:(day5作业:购物车(1))