Discuss / Python / 作业,看了大家的答案觉得自己是在是太笨了

作业,看了大家的答案觉得自己是在是太笨了

Topic source

1.def normalize(name): start=name[0] end=name[1:len(name)] s=start.upper() e=end.lower() return(s+e) print(list((map(normalize,['adam','Lisa','barT'])))) 2.from functools import reduce

def prod(L): def f(x,y): return x*y return reduce(f,L) print(prod([3,5,7,9])) 3.from functools import reduce

def str2float(): s=input('please input the str you want to convert:') for i in range(len(s)): if s[i]=='.': point=i int_part=s[0:point] float_part=s[point+1:len(s)] def f(x,y): return x10+y def char2num(s): digits={'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9} return digits[s] int_part_num=reduce(f,map(char2num,int_part)) float_part_num=reduce(f,map(char2num,float_part))/10*len(float_part) return int_part_num+float_part_num print(str2float())


  • 1

Reply