Discuss / Python / 第三题参考了大神的split方法,我一直在纠结那个点怎么班,也没办法写进密码本里,即使写进去了也不好计算

第三题参考了大神的split方法,我一直在纠结那个点怎么班,也没办法写进密码本里,即使写进去了也不好计算

Topic source

1》

def normalize(name): return name[0].upper()+name[1:].lower() 2》

def prod(L): def multiplication(a,b): return ab return reduce(multiplication,L) 3》 def char2num(x): digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,'.':'.'} return digits[x] def addd(a, b): return 10a+ b heads,lasts=s.split('.') return reduce(addd,map(char2num,heads))+(reduce(addd,map(char2num,lasts))/(10**len(lasts)))

耀光200412

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

return int(reduce(lambda x,y:x+y, s[0:s.index('.')])+reduce(lambda x,y:x+y, s[s.index('.')+1:]))/1000

#化成整数除以一千

耀光200412

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

return int(reduce(lambda x,y:x+y, s[0:s.index('.')])+reduce(lambda x,y:x+y, s[s.index('.')+1:]))/10**len(s[s.index('.')+1:])


  • 1

Reply