127k views
4 votes
1. Write a loop that reads positive integers from standard input, printing out those values that are even, each on a separate line. The loop terminates when it reads an integer that is not positive. 110132013301-1

1 Answer

0 votes

Answer:

while True:

num = int(input())

if num <= 0:

break

if num % 2 == 0:

print(num)

Step-by-step explanation:

The while loop runs indefinitely until it encounters a non-positive integer input. Within the loop, we read the integer input using input() and convert it to an integer using int(). We then check if the integer is positive or not. If it is not positive, we break out of the loop. If it is positive, we check if it is even by checking if the remainder after dividing by 2 is 0. If it is even, we print it out using print().

User Tjollans
by
7.2k points