Discuss / Python / 作业

作业

Topic source

第一题:

def normalize(name): return(name.capitalize())

第二题:

def prod(L): def f(x,y): return x*y return reduce(f,L)

第三题; DIGITS = {'.':'.','0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9} def char2num(s): return DIGITS[s] def f1(x,y): return x10+y n1=s.index('.') n2=len(s) intn=reduce(f1,map(char2num,s[:n1])) floatn=reduce(f1,map(char2num,s[n1+1:]))pow(10,-(n2-n1-1)) return intn+floatn


  • 1

Reply