-2

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.this is the code

expected output

the issue

ive tried to change the code a bunch of times, i dont really know what im doing im very new

Rakan
  • 15
  • 2
  • It looks like you want to stop once the user has entered ten numbers not the number ten, at least that’s my guess based on your desired output. – bob May 20 '23 at 20:18
  • 1
    [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551) – buran May 20 '23 at 20:42
  • 1
    Does this answer your question? [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – buran May 20 '23 at 20:44

2 Answers2

1

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")
darth baba
  • 1,277
  • 5
  • 13
0
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")
MoRe
  • 2,296
  • 2
  • 3
  • 23
  • this solved 1 issue, but now its just giving me an error and not going through with the second section of the code – Rakan May 20 '23 at 20:12
  • @Rakan you also need to turn the number into an `int` when you append it to your list. `numbers.append(int(num))` – SimonUnderwood May 20 '23 at 20:16