Discuss / Python / #练习三 我的思路是先得到整数123456,再得到小数点位置10**(-位置),得到123.456

#练习三 我的思路是先得到整数123456,再得到小数点位置10**(-位置),得到123.456

Topic source

城南梦想

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

#思路对不对?实现不了第一步--得到123456 from functools import reduce def str2float(s): if s == ".": return 0 d = {"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9} return d[s] def eg_redu3(x,y): return 10x + y def point_location(s): n = 0 for x in s: n = n +1 if x == ".": break return 10**(-(len(s) - n)) L3 = reduce(eg_redu3,map(str2float,"123.456"))point_location("123.456") print(L3)

城南梦想

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

from functools import reduce def str2float(s): if s == ".": return 0 d = {"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9} return d[s] def eg_redu3(x,y): return 10x + y def point_location(s): n = 0 for x in s: n = n +1 if x == ".": break return 10**(-(len(s) - n)) L3 = reduce(eg_redu3,map(str2float,"123.456"))point_location("123.456") print(L3)

城南梦想

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

10*x +y L3 = reduce(eg_redu3,map(str2float,"123.456"))乘号point_location("123.456")


  • 1

Reply