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

TheaBos Group Title

Looking for help with raw_input. In Exercise 1.8 Question #2, I used int(raw_input("Enter your number:") to get the number to count down from. But if someone enters a string instead of an integer it runs an error but I would rather redirect the user to another prompt. Is there a way to do this?

  • one year ago
  • one year ago

  • This Question is Closed
  1. shabari Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    http://answers.yahoo.com/question/index?qid=20100509023327AAqA7GE i think this link can answer your question

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

    Try using input instead of raw_input. And make sure you're storing your input to a variable. ex. number = input("What is your number? " )

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

    Thank you Shabari, your response was exactly what I was looking for. I was able to use the following code, which allowed me to give the user my own response instead of them receiving an error. try: base=int(raw_input("Enter your base:")) except ValueError: print "I don't understand your answer. Please use numbers only." base=int(raw_input("Enter your base:"))

    • one year ago
  4. TheaBos Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    mwilliams7! thanks for your response. I should've written the whole code. But I was trying to stop users from getting an error if they entered a string. If I used input I would still have the issue that if the user entered a string they would get an error.

    • 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.