Discuss / Python / 交作业

交作业

Topic source

梘香

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

#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 ... [Delete] [Delete and Lock User]

#1 丢了return a

梘香

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

#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