[Python] Modulo Operation for Odd & Even Number

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    I want to check the Even or Odd numbers therefore I have written the following code:

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

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


    It gives the following result:


    Which number do you want to check? 20
    This is an even number
    ​

    But when is change the above code inversely like this

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

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


    It gives the following result:


    Which number do you want to check? 20
    This is an odd number
    ​

    even if I change the "If modulo operation" to % 7 == 2 it would still give even as odd or vice versa

    Continue reading...

Compartilhe esta Página