Newbie Help
cronje_med
cronje_med at yahoo.com
Sat Jun 19 09:32:17 EDT 2004
Ok, so I'm a bit new at this, so please don't make fun of me too much.
I was trying to make a math function that wouldn't pull a NameError
if I didn't enter a number or variable containing a number. Here's
what I have:
def math(num):
if num.isdigit() == 1:
print "Is a number!"
return num
else:
print "Is not a number!"
return num
>>> math(5+5)
AttributeError: 'int' object has no attribute 'isdigit'
>>> math("5+5")
Is not a number!
'5+5'
>>> math("5+x")
Is not a number!
'5+x'
Any help anyone can provide would be great. Thank you.
More information about the Python-list
mailing list