def str2float(s):
dict1={'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'0':0,'.':'.'}
L=[]
for x in s:
m=dict1[x]
L.append(m)
for i in range(len(s)):
if s[i]=='.':
dot=i
L.pop(dot)
print(L)
def fx1(x1,y1):
return x1*10+y1
result=reduce(fx1,L)
p=0
while p<dot:
result=result*0.1
p=p+1
return result
Sign in to make a reply
海淀非典型帅哥
def str2float(s):
dict1={'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'0':0,'.':'.'}
L=[]
for x in s:
m=dict1[x]
L.append(m)
for i in range(len(s)):
if s[i]=='.':
dot=i
L.pop(dot)
print(L)
def fx1(x1,y1):
return x1*10+y1
result=reduce(fx1,L)
p=0
while p<dot:
result=result*0.1
p=p+1
return result