[Python] odd/even numbers Python giving me ALWAYS odd

Discussão em 'Python' iniciado por Stack, Setembro 25, 2024.

  1. Stack

    Stack Membro Participativo

    So I started practicing python recently and in this exercise I have make an if/else with odd/even numbers. I input a number and if its even I print "its even" else "its odd". I don't understand what is wrong with my code when I did exactly the same thing than the correct answer but saving it in a variable.

    I did this the calc works but always gives me odd

    number = int(input("Which number do you want to check? "))

    even = number % 2 == 0

    print(even)

    if number == even:
    print("This is an even number.")
    else:
    print("This is an odd number.")


    the solution was this

    if number % 2 == 0:
    print("This is an even number.")
    else:
    print("This is an odd number.")

    Continue reading...

Compartilhe esta Página