【Python Practice】Day 11 Question 38-43

'''
@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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tech沉思录

点赞加投币,感谢您的资瓷~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值