I'm trying to get number inputs from the user, till he reaches 10 and would break the while loop and go through the list and check if its odd or even.
ive tried to change the code a bunch of times, i dont really know what im doing im very new
I'm trying to get number inputs from the user, till he reaches 10 and would break the while loop and go through the list and check if its odd or even.
ive tried to change the code a bunch of times, i dont really know what im doing im very new
The Input function by default returns a str convert it to int or Float. And also append before checking or else you will not be able to check if 10 is even or odd.
numbers = []
while True:
i = int(input("Enter a Number: "))
numbers.append(i)
if i == 10:
break
for num in numbers:
if num%2 == 0:
print(f"{num} is even")
else:
print(f"{num} is odd")
if int(num) == 10
or
if num == '10'
your input type is string (str) and you can't compare it to int... first convert it to int using int()
then compare to 10
numbers = []
while True:
num = int(input("Enter a number: "))
if num == 10:
break
numbers.append(num)
for num in numbers:
if num % 2 == 0:
print(str(num) + " is even")
else:
print(str(num) + " is odd")