python练习

1.•利用 map() 函数,把用户输入的不规范的英文名字,变为首字母大写,其他小
写的规范名字。输入: ['adam', 'LISA', 'barT'] ,输出: ['Adam', 'Lisa',
'Bart'] 。
In [4]: def fun(x):
    return x.title()
   ...:

In [5]: map(fun,['adam', 'LISA', 'barT'])

Out[5]: ['Adam', 'Lisa', 'Bart']



2.•Python 提供的 sum() 函数可以接受一个 list 并求和,请编写一个 prod()
函数,可以接受一个 list 并利用 reduce() 求积。
In [7]: def prod(x,y):
    return x*y
   ...:

In [8]: reduce(prod,[1,2,3,4])

Out[8]: 24



3.
#!/usr/bin/env python
# coding:utf-8
_author_ = "tom"

'''
@author:houruiyun
@file:2.py
@contact:674211605.qq.com
@time:6/25/172:45 AM
@desc:
'''
print '''
      Welcome to shoping system
      可选择操作
      b:购买
      q:退出
      '''
goods  = [
    ('iphone',5800),
    ('book',100),
    ('bike',200)
]
buy = []
for k,v in enumerate(goods):
    print k,v
money = int(raw_input('请输入账户余额:'))
while True:
    oper = raw_input('plsase input your choice:')

    if oper == 'b':
        num = input('请选择商品编号:')
        price = goods[num][1]
        if money < price:
            print '账户余额不足'
        else:
            money = money - price
            print '%s to your shoping' % goods[num][0]
            buy.append(goods[num][0])
            print '''
                购买商品:%s
                消费金额:%s
                账户余额:%s
                ''' % (buy, price, money)

    else:
        exit()




4.登陆系统




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值