本文尝试用python实现简单的购物车程序。。。
基本要求:
用户输入工资,然后打印购物菜单用户可以不断的购买商品,直到余额不够为止
退出时打印用户已购买的商品和剩余金额。。。
代码:
#!/usr/env python
#coding:utf-8
import re,math
def get_customer_salary():
while True:
salary=raw_input('Please input your monthly salary(a positive integer):')
if __is_valid_num(salary):
return int(salary)
else:
print '[warn] Please input a valid number!'
def __is_valid_num(num):
p=re.compile(r'^\d+$')
m=p.match(num)
if m:
return True
else:
return False
def get_customer_selection():
while True:
selection=raw_input('Please enter the goods number you want to buy:')
if __is_valid_num(selection):
if __is_a_valid_selection(int(selection)):
return int(selection)
else:
print '[warn] Please enter a valid selection number'
else:
print '[

本文介绍了如何使用Python编程实现一个简单的购物车应用。程序能够记录用户的购买行为,并在退出时展示已购买的商品列表及剩余金额。
最低0.47元/天 解锁文章
1622

被折叠的 条评论
为什么被折叠?



