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?

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

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?

MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

http://answers.yahoo.com/question/index?qid=20100509023327AAqA7GE i think this link can answer your question
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? " )
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:"))

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

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.

Not the answer you are looking for?

Search for more explanations.

Ask your own question