hi, im trying to learn python and this is giving me

>>> x=input("Enter a value: ")
if x % 2 ==0:
print ("even")
else:
print ("odd")

then when i execute:


Enter a number:

then i enter a number but it does not print even or odd. why?

You have to convert the string from the input to an integer.

x = int(input("Enter a value: "))

Remember you have to catch the exception that will be raised if the input is not a number.

I assume you are using the new Python3 version. The input() function replaces the old raw_input() function and returns a string. So follow vidaj's advice.

did that still not printing out even or odd

Works for me ...

x = int(input("Enter an integer value: "))
if x % 2 == 0:
    print("even")
else:
    print("odd")

Maybe your problem is that you are using the Python shell. Generally that it is only for testing one-liners. Write and run your programs from an IDE like IDLE (usually installed with your Python distribution), see:
http://www.daniweb.com/forums/post104834-1.html

got it thanks for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.