作业
Topic source# 利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字。输入:['adam', 'LISA', 'barT'],输出:['Adam', 'Lisa', 'Bart']:
def normalize(name):
return str.title(name)
# Python提供的sum()函数可以接受一个list并求和,请编写一个prod()函数,可以接受一个list并利用reduce()求积:
def prod(L):
def x(a, b):
return a * b
return reduce(x, L)
# 利用map和reduce编写一个str2float函数,把字符串'123.456'转换成浮点数123.456:
def str2float(s):
array = s.split('.', 1)
decimal = array[1]
integer = array[0]
number = int(integer) + (int(decimal) * (1 / (10 ** len(decimal))))
return number
- 1
小毛心的哥哥酱紫