Discuss / Python / 作业(只列出需要写的代码)

作业(只列出需要写的代码)

Topic source

IM_Dull

#1 Created at ... [Delete] [Delete and Lock User]

第一题:

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

第二题:

def prod(L): def a(x,y): return x*y b = reduce(a,L) return b

第三题: DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,'.':'.'} def char2num(a): return DIGITS[a] def intsum(x,y): return x10+y def floatsum(m,n): return m0.1+n def fn(L): for i in range(len(L)): if L[i] == '.': dot = i int1 = L[0:dot] float1 = L[:dot:-1] int2 = reduce(intsum,int1) float2 = reduce(floatsum,float1) whole = int2+float2*0.1 return whole L1 = list(map(char2num,s)) return fn(L1)


  • 1

Reply