首页 > 代码库 > day24,python
day24,python
今日作业
有两个列表,分别存放来老男孩报名学习linux和python课程的学生名字
linux=[‘钢弹‘,‘小壁虎‘,‘小虎比‘,‘alex‘,‘wupeiqi‘,‘yuanhao‘]
python=[‘dragon‘,‘钢弹‘,‘zhejiangF4‘,‘小虎比‘]
问题一:得出既报名linux又报名python的学生列表
问题二:得出只报名linux,而没有报名python的学生列表
问题三:得出只报名python,而没有报名linux的学生列表
-------------------------------------------------------------------------------------
#作业1,2,3
i=[i for i in linux if i in python]
print(i)
i=[ i for i in linux if not i in python]
print(i)
i=[i for i in python if not i in linux]
print(i)
-----------------------------------------------------------------------------------------------
shares={
‘IBM‘:36.6,
‘lenovo‘:27.3,
‘huawei‘:40.3,
‘oldboy‘:3.2,
‘ocean‘:20.1
}
问题一:得出股票价格大于30的股票名字列表
for i in shares:
if shares[i] > 30:
print (i)
------------------------------------------------------------
i=[i for i in shares if shares[i] > 30]
print(i)
----------------------------------------------------------------------
问题二:求出所有股票的总价格
print((i for i in shares.values()))
----------------------------------------------------------------
作业3
l=[10,2,3,4,5,6,7]
得到一个新列表l1,新列表中每个元素是l中对应每个元素值的平方
过滤出l1中大于40的值,然后求和
---------------------------------------------------------------------------------------
l = [10, 2, 3, 4, 5, 6, 7]
l1=[ i*i for i in l]
print( sum( i for i in l1 if i >40 ))
day24,python