1.利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字。输入[‘adam’,’LISA’,’barT’],输出:[‘Adam’,’Lisa’,’Bart’]。
2.Python提供的sum()函数可以接受一个list并求和,请编写一个prod()函数,可以接受一个list并利用reduce()求积。
3.
#!/usr/bin/env python
#coding:utf-8
shoplist = []
productlist = [('Iphone',5800),('book',158),('bike',1000)]
salary = raw_input('Plz input your salary:')
if salary.isdigit():
salary = int(salary)
while True:
for i,v in enumerate(productlist):
print i,v
num = raw_input('Plz input the num of product:')
if num.isdigit():
num = int(num)
if num < len(productlist) and num >= 0:
product = productlist[num]
if product[1] <= salary:
shoplist.append(product[0])
salary = salary - product[1]
print 'Added %s into shopping cart,balance:%s,'%(p_item[0],salary)
else:
print 'Balance is not suffcient'
else:
print 'The num of product is not exist'
elif num == 'q':
for p in shoplist:
print 'Your shopping list is %s' %p
print 'Your balance is %s' %salary
exit(0)
else:
print 'ErrorType'
测试: