473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

need help with python

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...

May 12 '07 #1
12 2973
On 11 May 2007 18:47:27 -0700, ad*******@hotmail.com
<ad*******@hotmail.comwrote:
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...
I'm making a couple of assumptions here (correct me if I'm wrong):

1. You're using windows
2. You double clicked on the .py file

What this does is open up a new terminal window and start execution of
the program. The program will execute to completion and then the
window will close automatically without waiting for you to tell it to
(lovely isn't it?). To get around this you have a couple options:

1. Run the script from the command line
2. Put this at the end of the .py file: input('Press ENTER to continue')

Ian
May 12 '07 #2
On May 11, 9:11 pm, "Ian Clark" <turb...@gmail.comwrote:
On 11 May 2007 18:47:27 -0700, adamur...@hotmail.com

<adamur...@hotmail.comwrote:
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...

I'm making a couple of assumptions here (correct me if I'm wrong):

1. You're using windows
2. You double clicked on the .py file

What this does is open up a new terminal window and start execution of
the program. The program will execute to completion and then the
window will close automatically without waiting for you to tell it to
(lovely isn't it?). To get around this you have a couple options:

1. Run the script from the command line
2. Put this at the end of the .py file: input('Press ENTER to continue')

Ian
ok u used a bunch of fancy words in there... im not sure what a .py
file is... i am using windows... i dont know what a terminal window is
but im gonna asume that it is when you click the python thing... ya i
kinda understand what ur sayin but the thing is i wanted it to give
feedback to my question and why would it do that... hmmm very
confusing... im not sure how to run the script from the command
line... oh yeah the enter thing worked. thanks for that... oh the
command line must be the lil black box... if i put it there then it
will give me a bunch of syntax this and error that kinda stuff...
thats why im putin it in the notepad and plus the tutorial said to...

May 12 '07 #3
On May 11, 8:47 pm, adamur...@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

May 12 '07 #4
On May 11, 9:34 pm, Paul McGuire <p...@austin.rr.comwrote:
On May 11, 8:47 pm, adamur...@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.

May 12 '07 #5
On May 11, 9:41 pm, adamur...@hotmail.com wrote:
On May 11, 9:34 pm, Paul McGuire <p...@austin.rr.comwrote:


On May 11, 8:47 pm, adamur...@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

May 12 '07 #6
On May 11, 10:16 pm, Paul McGuire <p...@austin.rr.comwrote:
On May 11, 9:41 pm, adamur...@hotmail.com wrote:
On May 11, 9:34 pm, Paul McGuire <p...@austin.rr.comwrote:
On May 11, 8:47 pm, adamur...@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.

May 12 '07 #7
On May 11, 10:37 pm, adamur...@hotmail.com wrote:
On May 11, 10:16 pm, Paul McGuire <p...@austin.rr.comwrote:


On May 11, 9:41 pm, adamur...@hotmail.com wrote:
On May 11, 9:34 pm, Paul McGuire <p...@austin.rr.comwrote:
On May 11, 8:47 pm, adamur...@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.- Hide quoted text -

- Show quoted text -
Again, this runs just fine for me. Here is the output when run within
SciTE:
Welcome to the Area calculation program
-------------

Please select a shape:
1 Rectangle
2 Circle
1
Please enter the height: 10
Please enter the width: 20
The area is 200
Welcome to the Area calculation program
-------------

Please select a shape:
1 Rectangle
2 Circle
2
Please enter the radius: 10
The area is 314.0
It seems like you are still struggling with mechanics of files,
directories, etc., although your last post indicates you're making
some progress there.

Now for a better posting hint. When you tell us "Now it still won't
run my other program", this isn't really enough to go on. What
happens when you type in "python area.py" (assuming that you have used
the 'cd' command to change your directory to the one containing
area.py)? When you post that something doesn't work, copy/paste the
error messages themselves into the post, and the actual Python code
that you ran.

But your problems do not seem to be Python problems at all, just OS
and script execution mechanics.

-- Paul

May 12 '07 #8
I'm not sure how you installed Python, or how you are using it, but I
made something last year to help Windows XP users who are brand new to
Python and can't get things to run, etc.

You might try either jumping into somewhere midway, or if you keep
having trouble, uninstall whatever you installed and start over using
this:

http://www.richarddooling.com/index....o-hello-world/

If that link breaks, use this:

http://tinyurl.com/w7wgp

Good luck.

rd
May 12 '07 #9
On May 12, 11:55 am, BartlebyScrivener <bscrivene...@gmail.comwrote:
I'm not sure how you installed Python, or how you are using it, but I
made something last year to help Windows XP users who are brand new to
Python and can't get things to run, etc.

You might try either jumping into somewhere midway, or if you keep
having trouble, uninstall whatever you installed and start over using
this:

http://www.richarddooling.com/index....on-on-xp-7-min...

If that link breaks, use this:

http://tinyurl.com/w7wgp

Good luck.

rd
That is one of my problems, I don't know exactly how the whole command
line thing works. The other day, I got it to open python by itself,
but I accidentally closed the window and couldn't get it to work
again. I know how to do file paths and stuff but I'm not sure what to
put directly after it says C:\Documents and Settings\HP_Owner>. Do I
leave it like that and then put the next location in the line? Like
this:
C:\Documents and Settings\HP_OwnerPython 2.5.1\Python area.py
Or is that wrong. I've already uninstalled and reinstalled because I
couldn't copy and paste it to another location, so I just reinstalled
it to HP_Owner. I'll try that link.
Thanks.

May 13 '07 #10
On May 13, 10:10 am, adamur...@hotmail.com wrote:
On May 12, 11:55 am, BartlebyScrivener <bscrivene...@gmail.comwrote:


I'm not sure how you installed Python, or how you are using it, but I
made something last year to help Windows XP users who are brand new to
Python and can't get things to run, etc.
You might try either jumping into somewhere midway, or if you keep
having trouble, uninstall whatever you installed and start over using
this:
http://www.richarddooling.com/index....on-on-xp-7-min...
If that link breaks, use this:
http://tinyurl.com/w7wgp
Good luck.
rd

That is one of my problems, I don't know exactly how the whole command
line thing works. The other day, I got it to open python by itself,
but I accidentally closed the window and couldn't get it to work
again. I know how to do file paths and stuff but I'm not sure what to
put directly after it says C:\Documents and Settings\HP_Owner>. Do I
leave it like that and then put the next location in the line? Like
this:
C:\Documents and Settings\HP_OwnerPython 2.5.1\Python area.py
Or is that wrong. I've already uninstalled and reinstalled because I
couldn't copy and paste it to another location, so I just reinstalled
it to HP_Owner. I'll try that link.
Thanks.- Hide quoted text -

- Show quoted text -
cd <new directory>

will change your current directory to <new directory>. Type "help"
after the "C:\Documents and Settings\HP_Owner>" (which is called the
'prompt') to get a summarized list of commands, or "help <command>" to
get help on that particular command. For instance try typing this at
the command line prompt:

help cd

and you'll get a lot more info on the cd command.

It sounds like a Windows tutorial would not be wasted time for you,
especially one that helps with the whole command line thing. You'll
learn about files, directories, deleting, renaming, and so on.

-- Paul

May 13 '07 #11
On May 13, 10:10 am, adamur...@hotmail.com wrote:
>
That is one of my problems, I don't know exactly how the whole command
line thing works.
That's why I pointed you to the link. The ActiveState distribution
will automatically add the correct paths to your environment and tell
Windows that .py files are executable Python files and so on.

Get ActiveState installed. Get comfortable with the Python IDE.

Then follow the instructions in Alan Gauld's tutorial.

http://www.freenetpages.co.uk/hp/alan.gauld/

Especially, in your case, the GETTING STARTED section, which includes
a subsection called "The Windows Command Prompt"

rd

May 13 '07 #12
ad*******@hotmail.com wrote:
On May 11, 10:16 pm, Paul McGuire <p...@austin.rr.comwrote:
>On May 11, 9:41 pm, adamur...@hotmail.com wrote:
[... much ellided ...]

["ellided" is a fancy word for "left out" or "replaced
with ellipses."]
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.
Idle is an "IDE" (integrated development environment). It's sort
of like an editor and a "terminal window" ("command shell") combined.
The different colors are the result of a feature called "syntax
highlighting" which is available in most of the modern IDEs and better
text editors.

To "get the black window to come up" use the [Start] menu, choose
the "Run" option and type in the name of the program: "cmd" (then
hit [Enter]).

You can can also find it if you chase far enough down the various
sub-menus off the [Start] menu.

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:
Yes it's because of where you saved them and because of where the
command prompt (The C:\thing that you see inside the "terminal window").

Rather than moving your .py files to wherever your prompt is pointing,
it's generally better to change your prompt to point to the right place.

For example if you've been saving you .py files to "C:\My Documents" then
type:

cd "\My Documents"

... (with the quotes around it).

Then try to run your files from there.
# 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.
The pound signs are used by Python to mark "comments" (stuff the
Python interpreter ignores; that's there just as hints and reminders
to humans who are reading the source code).

So, from the first # sign on a line until the end of the line Python
is ignoring everything.

The only exceptions to this rule are when the # is inside quotes:

print "This is technically called an octothorpe: #. See?"

... in that line the octothorpe (#) is part of a quoted string
so it and the text following it are NOT ignored.

Incidentally, I would use the raw_input() function in place of
the input() function that these examples have been using.

The problem with the Python input() function is that it parses
the input as if it were Python code. So it will raise an
exception for any input you enter which is NOT valid, legal
Python code. (So far you've been lucky in that you've only been
using it to enter simple numbers, which are, of course, valid
Python expressions.

You can actually get away with inserting one line:

input = raw_input

... near the beginning of any of your code examples to alleviate
this issue. The raw_input() function will accept any string you can
enter up to the first [Enter] key. (Actually on my platform, Linux,
it's possible to embed newline and/or carriage return characters
--- the ASCII characters which are normally generated by the [Enter]
key on various computing platforms --- into a raw_input() value by
preceding each of them with a Ctrl-V key. Just off hand I don't
know if that works under Windows using a command prompt window.
Just pointing that out for other readers to make the observation that
Python's raw_input() might not be as "raw" as you might expect).
--
Jim Dennis,
Starshine: Signed, Sealed, Delivered

Jun 10 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can...
9
by: Roy Smith | last post by:
I'm working on a prototype of a new application in Python. At some point, if this ever turns into a product, the powers that be will almost certainly demand that it be done in Perl. My job will...
10
by: Jeff Wagner | last post by:
I am in the process of learning Python (obsessively so). I've been through a few tutorials and read a Python book that was lent to me. I am now trying to put what I've learned to use by rewriting...
7
by: has | last post by:
<BLUSH> Careless talk costs lives, as they say. In my case, a throwaway comment that Python could trounce the notoriously underpowered and undersupported AppleScript language for "serious number...
7
by: Steve Menard | last post by:
Here is my problem. I have this library thats hosts another language within python, and allows that language to call back INTO python. All is good as long as the other languages calls back on...
45
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
2
by: Benji99 | last post by:
Hi guys, I'm starting to learn Python and so far am very impressed with it's possibilities. I do however need some help with certain things I'm trying to do which as of yet haven't managed to find...
2
by: Aaron | last post by:
I have a data sructure setup and I populate it in a loop like so: y=0 while X: DS.name = "ASDF" DS.ID = 1234 list = DS; y = y + 1
10
by: blah | last post by:
i m currently in a network (LAN). i started python because i heard that it has great ability for networking programs and/or scripts, but i m losing my motivation with python because there are sooo...
14
by: mistral | last post by:
Need compile python code, source is in html and starts with parameters: #!/bin/sh - "exec" "python" "-O" "$0" "$@" I have installed ActivePython for windows.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.