[Tutor] Beginning Python 3.4.0 Programmer:Stephen Mik: Cannot get input variable to make While Loop conditional to work

Walter Prins wprins at gmail.com
Tue Apr 22 02:12:09 CEST 2014


On 21 April 2014 19:12, Stephen Mik <mik.stephen at yahoo.com.dmarc.invalid> wrote:
> Dear Python Community:
>     I am new to Python,with only about a month's experience. I am writing
> Python 3.4.0 code that apparently isn't doing what it should be doing.
> Specifically, I am inputting or trying to input,a Sentry Variable to a While
> Loop. I want to test out the Main program" While" Loop before I add an inner
> "While" Loop. The program I have written,when run on the Python 3.4.0
> Shell,does not stop for input of the "While" Sentry Variable,it just gives a
> program error: "Value of smv_grandVariable undefined". What am I doing wrong
> here?

You are misunderstanding how input() works.  It is a function, which
means it returns a result, and takes one parameter which is a
prompt/message to display, e.g you should have something like this:

result = input('Input a string:')

This displays 'Input a string:' to the user and then waits for input,
after which it puts the inputted value into the variable 'result'.
That also hopefully explains the error message -- it's telling you
that 'smv_grandVariable', which you've given to input() and which
Python's duly trying to display is undefined.  (By the way, try to
pick a better name for that variable which suggests what its role is
supposed to be.)  Also see here:


More information about the Tutor mailing list