...

Test if input is number or string

Napsteren
02-25-2011, 10:51 AM
Hello CF

Im new to python, and Im struggling with a code here.

How do i test if the user input is a number or a string?

print("Hello")

i = raw_input("Type a number = ")

if not a number:
print("Illegal")

The ( If not a number ) is where i need my code..

Best Regards,

Nap

Kakao
02-25-2011, 01:00 PM
i = raw_input("Type a number = ")
try:
i = float(i)
except ValueError:
print("Illegal")



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum