[Tutor] Help on IF Statements
Daniel Yoo
dyoo@hkn.EECS.Berkeley.EDU
Mon, 31 Jul 2000 23:29:02 -0700 (PDT)
Dear Emo,
Hello! Ok, let's take a look.
On Mon, 31 Jul 2000, emo sofia wrote:
> 1. to type it: but the result is err
> >>> x = int(raw_input("Please enter a number: "))
> Please enter a number:
> Traceback (innermost last):
> File "<pyshell#2>", line 1, in ?
> x = int(raw_input("Please enter a number: "))
> ValueError: invalid literal for int():
Hmm... this appears to work for me:
###
>>> x = int(raw_input("Please enter a number: "))
Please enter a number: 23
>>> x
23
###
However, if I press enter at the prompt instead, it'll trigger the same
error message:
###
>>> x = int(raw_input("Please enter a number: "))
Please enter a number:
Traceback (innermost last):
File "<stdin>", line 1, in ?
ValueError: invalid literal for int():
###
I'm not quite sure if that's what's happening with your program. You
might want to temporarely hard-code values of 'x' into your program, since
you're learning about if-statements. Your programs seem fine --- it might
just be strangeness with input/output.
If you're familiar with your text editor and command prompt, you might
want to write your program into a '.py' file, and try using programs with
raw_input() there. Doing this might make things easier --- you can
correct typos without rewriting the whole section of code.