Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

madweekay

Hi, does anybody know how to determine whether an input string (from raw_input) is a float? I know isdigit() works for int types, but what of float types? Or, is the only solution converting the string to a float(),and then assuming the program will crash for non-float input values?

  • one year ago
  • one year ago

  • This Question is Closed
  1. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    depends on the language, but yes you can say Float.ParseFloat(string); in Java....

    • one year ago
  2. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    http://openstudy.com/study#/updates/50fba568e4b010aceb3312fb Someoen asked this yesterday in C it's Convert.

    • one year ago
  3. madweekay
    Best Response
    You've already chosen the best response.
    Medals 0

    I should clarify: This is for Python

    • one year ago
  4. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 1

    You could do something like: try: x = float( raw_input( "> " ) ) except: #handle it not being a float

    • one year ago
  5. madweekay
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks, this is pretty much what I'm going to do. I just wasn't sure if there was a built in function like isdigit()

    • one year ago
  6. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 1

    There are always regular expressions. "\d*\.?\d*" off the top of my head.

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.