The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > General Programming > Python


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags:

Closed Thread
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 06-10-2007, 04:21 PM
Chris R
Posts: n/a
[SOLVED] Ending a program in python?

I have two questions about specific commands in python.

When I run my programs in DOS, right after the program is finished, DOS closes- how do I avoid that? is there a command that will keep the window open? a pause of sorts?

The second question is about while loops. I have a while loop imbedded within another while loop. When the inside while loop becomes false, it displays a message- but then continues with the outside loop- what can I do if I just want the program to end when the inside loop is false?

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #2 (permalink)  
Old 06-10-2007, 04:22 PM
Paul P
Posts: n/a
First question:

You can use raw_input() to "pause" and keep the window open. This function prints its argument to the screen and waits for user input. For example, if I wanted to keep a dos prompt open, I might have as my last line of the program:

raw_input('Press <enter> to continue")

Second question:

breaking out of your outer loop is simple. just set a flag in your inner loop, and if the flag is true, break out of your outer loop. for example,

fBreak = False
for x in range(10):
....for y in range(10):
........sum = x + y
........if sum > 15:
............fBreak = True
............break
....if fBreak:
........break

Notes:
i use dots to represent spaces since this forum strips spaces from your text and i have not discovered a way to prevent that from occurring.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #3 (permalink)  
Old 06-10-2007, 04:22 PM
José
Posts: n/a
First answer:
why don't you use a Batch file to run your program?
Or, you can try to use a function to run the DOS command "pause", but it wouldn't be very pretty.

Second answer:
I don't know what you're willing to do with your loops, but I'm sorry to inform that I'm almost sure that you're doing it wrong.

You're doing this:

while condition1 :
while condition2 :
commands

But I think you're willing to do:

if condition1 :
while condition2 :
commands

or even:

while condition1 & condition2 :
commands

Regards.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Closed Thread


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 03:49 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50