need help with python

Paul McGuire ptmcg at austin.rr.com
Fri May 11 22:34:09 EDT 2007


On May 11, 8:47 pm, adamur... at hotmail.com wrote:
> ya so im pretty much a newb to this whole python thing... its pretty
> cool but i just started today and im already having trouble.  i
> started to use a tutorial that i found somewhere and i followed the
> instructions and couldnt get the correct results.  heres the code
> stuff...
>
> temperature=input("what is the temperature of the spam?")
> if temperature>50:
>         print "the salad is properly cooked."
> else:
>         print "cook the salad some more."
>
> ya i was trying to do that but when i told it what the spams
> temperature was, it just turned off... well it wasnt working at all at
> first until i realized that i hadnt been following the instructions
> completely correctly and that i was supposed to type that code up in a
> notepad then save and open with python... so ya thats when it asked me
> what temperature the spam was and i typed a number then it just closed
> itself... im not really sure what went wrong... itd be real nice if
> someone would be like a mentor or something...

Well, this list has a varying level of mentoring and newbie-tolerance,
with more latitude for people who have made some effort to start with
before posting things like "here's my homework problem, please send me
the working code so I can hand it in."

I just ran your code interactively at the Python prompt, and it runs
just fine.  See?

>>> temperature=input("what is the temperature of the spam?")
what is the temperature of the spam?55
>>> if temperature>50:
...         print "the salad is properly cooked."
... else:
...         print "the salad is properly cooked."
...
the salad is properly cooked.

I think the problem you are having is that, when you run your program
by double-clicking on the xyz.py file in a file browser, the OS
(Windows, I assume?) opens a separate console window, and runs the
program, and then at the end of the program, CLOSES the window.  I
think your code is running just fine, I think your "the salad is
whatever" messages get printed out, but afterward, your program ends,
so the window closes before you can see how your salad turned out.

A simple workaround you can do is to add to the end of your program
this statement:

input("<press return to end program>")

This will cause the process to stop and wait for you to press the
RETURN key, giving you time to stop and admire your salad results
before closing the window.

One final note: many people post in a "write like I talk" style.  This
is okay while telling your story ("well it wasn't working at all at
first..."), and the ee cummings all-lower-case is passable, but please
drop the "ya"s.  They are a verbal tic that may be okay in person, but
do not translate at all to written posts.  At least you don't say
"like" every other word, and I thank you for that! :)

You can get a sense of other writing styles by reading through the
comp.lang.python archives.  I would also recommend that you might find
more folks in the "just getting started" phase posting to the python-
tutor mailing list (go to http://mail.python.org/mailman/listinfo/tutor),
and you can skim through posts there for many introductory topics.

Good luck to you, and welcome to Python!

-- Paul




More information about the Python-list mailing list