PDA

View Full Version : python program


abhilashm86
January 21st, 2009, 06:58 AM
i am just starting to learn python,when i complied following conditonal statement,compiler gave error,i just don't find any error here

x=raw_input ('entre x value')

if x%2 == 0:
print x," is even"
else:
print x," is odd"


error by compiler,
abhilash@abhi:~$ python p1.py
entre x value 10
Traceback (most recent call last):
File "p1.py", line 3, in <module>
if x%2 == 0:
TypeError: not all arguments converted during string formatting

tabor
January 28th, 2009, 02:06 PM
Use x = input("entre x value")

instead of raw_input, and your program will work. The problem is that with raw_input it will keep the number as a string, instead of an integer.

Taidgh
January 28th, 2009, 03:39 PM
Or alternatively, int(x).