Discuss / Python / 上面乱码了重发一把 小白作业 望指导

上面乱码了重发一把 小白作业 望指导

Topic source

from functools import reduce

第一题

def FirstStrToDX(s): return s[0].upper()+s[1:].lower()

L1 = ['adam', 'LISA', 'barT'] L2 = list(map(FirstStrToDX, L1)) print(L2)

第二题

def chengfa(x,y): return x*y

def prod3(L3): return reduce(chengfa,L3)

def prod31(L3): return reduce(lambda x,y:x*y,L3)

print(prod3([3, 5, 7, 9]))

第三题

def str2float(s): s=s.split('.') if len(s)==1: return reduce(lambda x,y:x10+y,map(int,s[0])) else: return reduce(lambda x,y:x10+y,map(int,s[0]+s[1]))/pow(10,len(s[1]))

print(str2float('123.456789')) print(str2float('0.123')) print(str2float('123.')) print(str2float('123'))

meltlight

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

mark一下

你这个写的也太好了吧,惭愧,以后不敢自称小白咯。

JoyElaine

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

向你学习~

JoyElaine

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

太棒了~

_盛盛_

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

第三题不应该用int()函数,不然都不需要写这么多了,一个int()就搞定了

塩鱼dalao

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

学习,第一题为什么要用list啊? L2=list(map(guifan,L1)) 看不懂为什么,请大佬支教


  • 1

Reply