Quote:
|
Originally Posted by Volkan
sorry but i do not understand how i would implement that while loop into my program? could give some example code?
|
A while loop repeats until a condition fails. For instance:
x = 0
while x < 5:
x = x + 1 In the above program x starts as zero. The program then keeps adding 1 to x, but only while x is less than five. This is why it's called a 'while' loop. Because it will keep repeating the same bit of code
while x is less than five.
When x reaches five, the condition is broken, and the loop exits.
What you want to do is keep asking the user questions while he does not want to quit. Here's a simple loop example that controlled by user input:
answer = 0
while answer != 2
print """Choose an option:
1. Continue the loop.
2. Exit the loop."""
answer = input("> ") I'm sure someone else will point out that raw_input is usually preferable to input. But I'll leave that for someone else to explain, because I have to go
