0
点赞
收藏
分享

微信扫一扫

【Python Practice】Day 11 Question 38-43

耳一文 2023-03-04 阅读 25


'''
@Author: your name
@Date: 2020-07-16 16:15:44
@LastEditTime: 2020-07-16 18:01:28
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \vscode_py\day11.py
'''
# Question 38
# 将输入分两行输出
def Q38():
str=input().split()
l=[int(i) for i in str]
print(l)
t=tuple(l)
print(t)
print(t[:5])
print(t[5:])

# Question 39
# 找到tuple中的偶数
def Q39():
t=(1,2,3,4,5,6,7,8,9,10)
tp1=tuple(i for i in t if i%2==0)
print(tp1)

# Question 40
# 读取输入,输出对应的str
def Q40():
l=input()
if l=='yes' or l=='YES' or l=='Yes':
print("Yes")
else:
print("No")


# Question 41
# 使用map计算list中元素的平方
def Q41():
l=[1,2,3,4,5,6,7,8,9,10]
s=map(lambda x: x**2,l)
print(list(s))

# Question 42
# 使用map计算偶数的平方
def Q42():
l=[1,2,3,4,5,6,7,8,9,10]
r=map(lambda x:x**2,filter(lambda x:x<5,l)) # filter是过滤list中符合要求的点
print(list(r))

# Question 43
# 使用filter将1-20中的偶数,生成一个list

def even(x):
return x % 2==0
def Q43():
l=[i for i in range(1,21)]
# r=filter(lambda x:x%2==0,l)
r=filter(even,l) #输入条件和容器,对容器中的每一个元素判断条件,满足则输出

print(list(r))

if __name__ == "__main__":
# Q38()

# Q39()

# Q40()

# Q41()

# Q42()

Q43()


举报

相关推荐

0 条评论