0
Stuck on homework question.
the question is :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. I have this what's wrong with it? thanks! x = input(int()) while x>= -1: print(x) x % -1 if x == -1: terminate
3 ответов
+ 2
The first conditional should be if (x >= 0), then, if (x%2 = 0) print.
The first problem that I see is the final "-1". If input is "-2" or less it will work anyway. It should be if (x < 0)
Im not familiar with Pythons syntax but you get the point.
+ 2
while 1:
x = int(input("Please Enter a Number : "))
if (x >= -1):
if (x%2 == 0):
for i in range(x):
if(i%2 == 0):
print(str(i) + ' is even number \n')
else:
print("you entered a negative number, program terminated..! ")