Python练习07-09

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'

测试:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值