Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > Python

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-25-2011, 10:51 AM   PM User | #1
Napsteren
New Coder

 
Join Date: Oct 2010
Posts: 40
Thanks: 2
Thanked 0 Times in 0 Posts
Napsteren is an unknown quantity at this point
Test if input is number or string

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
Napsteren is offline   Reply With Quote
Old 02-25-2011, 01:00 PM   PM User | #2
Kakao
Regular Coder

 
Join Date: Mar 2006
Location: Brasília, Brazil
Posts: 153
Thanks: 0
Thanked 0 Times in 0 Posts
Kakao is on a distinguished road
Code:
i = raw_input("Type a number = ")
try:
   i = float(i)
except ValueError:
   print("Illegal")
Kakao is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:02 PM.


Advertisement
Log in to turn off these ads.