关于作者

Discuss / Python / 第三题

第三题

问题来源

豆芽太羊

#1 Created at ...

#--coding:utf-8-- from functools import reduce def char2float(c): dict={'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'.':'.'} return dict[c] def fun1(x,y): return x10+y def fun2(x,y): return 0.1x+y def str2float(s): L=list(map(char2float,s)) i=0 while i<=len(L): if L[i]=='.': break else: i=i+1 fore=reduce(fun1,L[0:i]) back=reduce(fun2,L[len(L):i:-1]) return fore+0.1*back print('123.4567->',str2float('123.4567'),sep='')

豆芽太羊

#2 Created at ...

while循环部分可以用i=s.find('.')来代替


  • 1

Reply

WARNING: You are using an old browser that does not support HTML5. Please choose a modern browser (Chrome / Microsoft Edge / Firefox / Sarafi) to get a good experience.