need help with python

adamurbas at hotmail.com adamurbas at hotmail.com
Fri May 11 23:37:20 EDT 2007


On May 11, 10:16 pm, Paul McGuire <p... at austin.rr.com> wrote:
> On May 11, 9:41 pm, adamur... at hotmail.com wrote:
>
>
>
> > On May 11, 9:34 pm, Paul McGuire <p... at austin.rr.com> wrote:
>
> > > 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 tohttp://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
>
> > well... i just discovered another of my mistakes.  i was writing it in
> > notepad and not saving it as .py  silly me... hoho ya that input thing
> > to get it to make u press enter worked tho... but only with that
> > one... ive got another one that i cant get to work even with the input
> > message to press enter.  Sorry about the bad grammar.  I'm used to
> > Myspace where no one gives a particular hoot about how you type.  I
> > hope this is better.  I will follow that link though.  Thanks for the
> > help.- Hide quoted text -
>
> > - Show quoted text -
>
> It's possible that your next program has a runtime error, which will
> raise an exception that, if not handled using try-except, will cause
> the program to exit with a message (a message that will flash by and
> then disappear, as the window closes immediately).
>
> One thing you should try is to run your python programs using a
> terminal window (sometimes called a "console window", or "the command
> line").  There are several ways to open one of these, the simplest on
> Windows is to click the "Start" button in the lower left corner,
> select "Run...", and enter the command "cmd".  This will open up one
> of these white-letters-on-black-background windows for typing system
> commands.  From this command line, you can run your Python programs by
> typing "python blah.py" where blah.py is the name of your Python
> script (which you created in Notepad and saved as blah.py.  By running
> scripts this way, you will get to see *all* of your program output,
> without having the window close on you. (and please don't name all
> your scripts "blah.py", you should pick different names...)
>
> Another thing you might try is downloading and installing SciTE for
> Windows - a free super-Notepad, with built-in support for editing *and
> running* Python scripts.  Enter your Python code, save it as
> "whatever.py", then press F5 - the editor will split down the middle,
> keeping your program in the left half, and show the output messages
> and exceptions on the right.  I find this much easier than going back
> and forth between Notepad and a terminal window.  Other developer
> editors (often called "IDE"s for Interactive Development Environment)
> work similarly, such as pythonwin or IDLE - there are many others to
> choose from, but coming from Notepad, SciTE will not be a big step,
> but will move you forward.
>
> -- Paul

I was looking around in my Python folder and saw something to do with
that IDLE thing you were talking about.  When I right clicked on a .py
file, it said edit with IDLE.  I opened it and it was my code but each
line was a different color.  It looked confusing so I decide to save
it for later.  I knew that I could get the run thing to do the command
thing, but I had forgotten how to get the black window to come up.

Ok.  Well, I tried to us the cmd window.  It says python: can't open
file 'area.py'  I'm guessing that's not good.  It won't open any of
my .py files.  It's because of where I saved them.  I can see how this
i going to work now.  Ok so I'll just move them to the place that the
command line says.  Now it still won't run my other program:

# Area calculation program

print "Welcome to the Area calculation program"
print "-------------"
print

# Print out the menu:
print "Please select a shape:"
print "1  Rectangle"
print "2  Circle"

# Get the user's choice:
shape = input("> ")

# Calculate the area:
if shape == 1:
    height = input("Please enter the height: ")
    width = input("Please enter the width: ")
    area = height*width
    print "The area is", area
else:
    radius = input("Please enter the radius: ")
    area = 3.14*(radius**2)
    print "The area is", area

Perhaps it isn't written correctly.  I don't think it likes the pound
signs.  I'm not sure.  But, I did go to that mailing list you
recommended.  Thanks for that.




More information about the Python-list mailing list