关于作者

Discuss / Python / 交作业

交作业

问题来源

梘香

#1 Created at ...

#1. def normalize(name): a=name[0].upper()+name[1:].lower()

print(normalize(input('请输入英文名:')))

#2. def prod(L): return reduce(lambda x,y:x*y,L)

print(prod([1,2,3,4]))

#3. def str2float(s): n=s.index('.') return float(s[:n])+float('0.'+s[n+1:])

print(str2float(input("请输入小数:")))

梘香

#2 Created at ...

#1 丢了return a

梘香

#3 Created at ...

#3 def char2num(s): return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7': 7,'8':8,'9':9}[s]

def str2float(s): n=s.index('.') return reduce(lambda x,y:x10+y, map(char2num,s[:n]))+0.1reduce(lambda x,y:x*0.1+y, map(char2num,s[n+1:][::-1]))


  • 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.