[Python] Trying to create an odd even function

Discussão em 'Python' iniciado por Stack, Agosto 29, 2025.

  1. Stack

    Stack Membro Participativo

    i am trying to create a function where when i call the function it prompts the user to enter an integer and returns whether it is even or odd. i am trying to make it so that my code prints an error to the console when nothing is entered or when a string is entered, i have gotten it to the point whereby if i enter a number it returns number, "is an even number" if it is even and number, "is not an even number" if it is not even here is my code below i am using python 2.7.3

    def is_even():
    x = int(raw_input("Enter number"))
    if x % 2 == 0:
    return x, "is an even number"
    else:
    return x, "is not an even number"

    print is_even()

    Continue reading...

Compartilhe esta Página