0

How do i stop python from giving me an ValueError everytime I put a letter in? Input must be a number! Using Python 2.7.3

1 Answer 1

1

Instead of using input(), use raw_input(), which returns a string.

input() is equivalent to eval(raw_input()) in Python 2.7. Hence, if you input a letter (let's say 'a'), it will try look for a variable called 'a'. If there isn't one, a NameError is raised.

if you're working with numbers, then you can always call int() on the input received by using raw_input(). You could also use a try: except: structure to catch any ValueErrors incase the input is not a number.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.