import random
# 创建100-200之间的偶数列表
even_numbers =[x for x inrange(100,201)if x %2==0]# 从偶数列表中随机选择5个不重复的数字
result = random.sample(even_numbers,5)print(result)#输出结果:# [192, 168, 180, 100, 196]
import random
# 创建1-1000之间的偶数列表
even_numbers =[x for x inrange(1,1000)if x %5==0and x %7==0]# 从列表中随机选择5个数字
result = random.sample(even_numbers,5)print(result)#输出结果:# [70, 805, 595, 35, 735]
subjects =["I","You"]
verbs =["Play","Love"]
objects =["Hockey","Football"]for subject in subjects:for verb in verbs:for obj in objects:sentence ='%s %s %s'%(subject,verb,obj)print(sentence)#输出结果:# I Play Hockey# I Play Football# I Love Hockey# I Love Football# You Play Hockey# You Play Football# You Love Hockey# You Love Football
78、问题:请写一个程序打印列表,删除数组中的偶数[5,6,77,45,22,12,24]
lis =[5,6,77,45,22,12,24]print([i for i in lis if i %2!=0])# 输出结果:# [5, 77, 45]