这样:
N=int(input("请输入一个整数N(N < 300):"))i=0
n=0
while n<N:
i+=1
if i%7==0 or i%10==7:
n+=1
print(i)
else:
pass
输出结果:
代码为:
import redef xiny(x, y):
return bool(re.findall(x, y))
i = 1
while i <= 100:
if i % 7 == 0 or xiny("7", str(i)) == True:
print("过", end=",")
else:
print(i, end=",")
i = i + 1
输出结果:
1,2,3,4,5,6,过,8,9,10,11,12,13,过,15,16,过,18,19,20,过,22,23,24,25,26,过,过,29,30,31,32,33,34,过,36,过,38,39,40,41,过,43,44,45,46,过,48,过,50,51,52,53,54,55,过,过,58,59,60,61,62,过,64,65,66,过,68,69,过,过,过,过,过,过,过,过,过,过,80,81,82,83,过,85,86,过,88,89,90,过,92,93,94,95,96,过,过,99,100,1、Python猜拳小游戏代码:
2、import random #导入随机模块
3、
4、num = 1
5、yin_num = 0
6、shu_num = 0
7、while num 2:
12、 print('不能出大于2的值')
13、 else:
14、 data = ['石头', '剪刀', '布']
15、 com = random.randint(0, 2)
16、 print(您出的是{},电脑出的是{}.format(data[user], data[com]))
17、 if user == com:
18、 print('平局')
19、 continue
20、 elif (user == 0 and com == 1) or (user == 1 and com == 2) or (user == 2 and com == 0):
21、 print('你赢了')
22、 yin_num += 1
23、 else:
24、 print('你输了')
25、 shu_num += 1
26、 num += 1
27、Python数字炸弹小游戏代码:
28、import random
29、import time
30、
31、bomb = random.randint(1, 99)
32、print(bomb)
33、start = 0
34、end = 99
35、while 1 == 1:
36、
37、 people = int(input('请输入{}到{}之间的数:'.format(start, end)))
38、 if people >bomb:
39、 print('大了')
40、 end = people
41、 elif people <bomb:
42、 print('小了')
43、 start = people
44、 else:
45、 print('BOOM!!!')
46、 break
47、 print('等待电脑了输入{}到{}之间的数:'.format(start, end))
48、 time.sleep(1)
49、 com = random.randint(start + 1, end - 1)
50、 print('电脑输入:{}'.format(com))
51、 if com >bomb:
52、 print('大了')
53、 end = com
54、 elif com <bomb:
55、 print('小了')
56、 start = com
57、 else:
58、 print('BOOM!!!')
59、 break