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