![]() |
|
|
|
| ||||||
|
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: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [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? |
| |
| |||
| 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. |
| |||
| 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. |
![]() |
| Thread Tools | |
| Display Modes | |
| |