Hardware Reference
In-Depth Information
continued
This is a common programming design pattern for a loop that runs at least once,
asks you if you want another go and, if you don't, it quits the loop. There are
many different ways to achieve this same goal in Python, but using a boolean
variable is quite a good way to do this, as it is very clear how the program works.
You won't be using it in this topic, but Python has a statement called break that
can be used to break out of loops. You could do some research on the Internet
to see how you could rewrite this loop to use a break statement instead, which
would remove the need for the boolean variable.
A boolean variable is a variable that holds one of two values—either True or
False . It is named after George Boole, who was a mathematician who did a lot
of work in the 1800s with formal logic, much of which underpins the foundations
of modern computing. You can read more about Boole here: http://en.wikipedia.
org/wiki/George_Boole.
Displaying the.Menu
A menu system is a very useful feature to add to your programs if they have lots of
options for you to choose from. This menu system prints all the available options and
then loops around, waiting for you to enter a number in the correct range. If you enter
a number that is out of range, it just prints the menu again to give you another try.
1. Modify the menu function and replace it with the following (make sure that you
get the indentation correct):
def menu():
while True:
print("DUPLICATOR MENU")
print(" 1. BUILD the duplicator room")
print(" 2. LIST files")
print(" 3. SCAN from duplicator room to file")
print(" 4. LOAD from file into duplicator room")
print(" 5. PRINT from duplicator room to player.pos")
print(" 6. CLEAN the duplicator room")
print(" 7. DEMOLISH the duplicator room")
print(" 8. QUIT")
choice = int(raw_input("please choose: "))
if choice < 1 or choice > 8:
 
 
Search WWH ::




Custom Search