我正在做这个任务:
Write a program that prints all even numbers less than the input number using the while loop.
The input format:
The maximum number N that varies from 1 to 200.
The output format:
All even numbers less than N in ascending order. Each number must be on a separate line.
N = int(input())
i = 0
while 200 >= N >= 1:
i += 1
if i % 2 == 0 and N > i:
print(i)
其输出如下:
10 # this is my input
2
4
6
8
但是关于时间的问题有一个错误
简单的代码是:
问题是while循环从不停止
while 200 >= N >= 1
在这种情况下,由于从不更改N的值,因此条件始终为true。也许你可以做更多类似的事情:相关问题 更多 >
编程相关推荐