习题
Topic source第三题写错了...
from functools import reduce pass //numList_2 = numList[dotLocation+1:] return num1 + num2/10 ** len(numList_2)
- 1
第三题写错了...
from functools import reduce pass //numList_2 = numList[dotLocation+1:] return num1 + num2/10 ** len(numList_2)
机修贾森
第一题
def normalize(name): return name.capitalize()
第二题
def prod(l): return reduce(lambda x, y: x * y, l)
第三题
def str2float(s): DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '.':'.'} def str2num(s): return DIGITS[s] numList = list(map(str2num, s)) dotLocation = numList.index('.') numList_1 = numList[:dotLocation] numList_2 = numList[dot_location+1:] def num2int(x,y): return x × 10 + y num1 = reduce(num2int, numList_1) num2 = reduce(num2int, numList_2) return num1 + num2/10 ** dotLocation