简单购物车

#简单购物车,要求如下:
实现打印商品详细信息,用户输入商品名和购买个数,则将商品名,价格,购买个数加入购物列表,如果输入为空或其他非法输入则要求用户重新输入 
msg_dic={
'apple':10,
'tesla':100000,
'mac':3000,
'lenovo':30000,
'chicken':10,
}
good_l=[]
while True:
    for k in msg_dic:
        print(k,msg_dic[k])
    name=input('商品名称:',).strip()
    while True:
        count=input('购买个数:')
        if count.isdigit():
            break
    good_l.append((name,msg_dic[name],int(count)))
    print(good_l)
    if len(name)==0 or name not in msg_dic:
        print('非法输入')
        continue

 

posted @ 2017-12-15 20:23  rjm123456  阅读(123)  评论(0编辑  收藏  举报