Discuss / Python / 作业代码--str2float

作业代码--str2float

Topic source

sofa_th

#1 Created at ... [Delete] [Delete and Lock User]
def str2num(ss):
	pos=ss.index('.')
	nn=ss.replace('.','')
	r=list(map(char2num,nn))
	res=reduce(fn,r)
	wei={'1':10,'2':100,'3':1000}
	t=str(len(nn)-pos)
	res=res/wei[(t)]
	return res
print('str2float')
print(str2num('123.456'))

  • 1

Reply