[Tutor] How do I get user input when running a python program?

Walter Prins wprins at gmail.com
Thu Mar 15 23:11:40 CET 2012


Hi Tamar,

On 15 March 2012 17:59, Tamar Osher <emeraldoffice at hotmail.com> wrote:
> Hi.  I am reading Python for the Absolute Beginner, finished chapter 4, and
> am trying to duplicate the author's games.  In order to know if I have
> properly created my new games, I need to get user input and see what
> happens.  How do I set things up on my computer so that I can get user input
> when my new program is being run?  I have Python 3.2.2 and a Windows7 64-bit
> computer.  I hope to hear from someone; thank you very much for helping me.
>  I am very appreciative!

Firstly, what version of the book are you using?  (Or more
specifically, what version of Python is the book using?)  You're just
setting yourself up for trouble if your book is using a substantially
different version of Python than you are.  (The first version of the
book, for example, came out in 2003 and uses Python 2.2...)  The
second edition came out around 2006 so probably also uses Python 2.x
so even if you're using that, I'd suggest you perhaps consider
uninstalling Python 3 and (for now at least) installing something
closer to what the book is using. (Sorry if this causes you trouble,
but IMHO it's probably better for you to not introduce more
unnecessary variables that make your learning more complicated that it
needs to be and using Python 3.x when your book is 2.x will make
things more complicated than it needs to be.)

Secondly, have you actually read the first 3 chapters?  I ask, because
by your question it appears you may not have, or may not have properly
absorbed the content.  For example, in the first chapter of the book
(at the least, the first version), your question is partially
answered.  I quote:

"*Waiting for the user*
================

The last line of the program:

raw_input("\n\nPress the Enter key to exit.")

displays the prompt "Press the Enter key to exit." and waits for the
user to press the Enter key.  Once the user presses the key, the
program ends. This is a nice trick to keep a console window open until
the user is done with an application."

Similarly, there's a section entitled "Getting user input" in chapter
2.  So, to echo Ramit, are you having trouble understanding how the
author does it in Chapter 1 & 2?  If not, what are you stuck on?

Regards,

Walter


More information about the Tutor mailing list