Dear Forum
I have tried several things to break the while loop - when I input a number outside the boundaries (1, 2, 3 )then it loops back to the top of the menu which is what I want but then doesn't stop.
Also can you explain how I can import the code with the line numbers as I know this makes it easier for you to check the code
import sys
#history subject
def history():
print ('welcome to History Quiz')
print('Please choose a topic')
print ('1.WW1\n2.WW2\n3.Boer\n')
#first menu
invalidInput=True
def main():
print ("Please choose a subject")
print ("1. History")
print ("2. Computer Science")
print ("3. Quit")
choice = int(input("Please enter choice"))
if choice == 1:
history()
invalidInput=False
elif choice ==2:
print("Computer science")
invalidInput=False
elif choice == 3:
sys.exit()
invalidInput=False
else:
print("incorrect input. Enter 1-3")
while invalidInput:
main()
#Thank you
Sorry but copying the code into the window it has lost all the indents, if you can explain how to copy the code into the forum window without losing the indents I would be grateful
Thank you
I have tried several things to break the while loop - when I input a number outside the boundaries (1, 2, 3 )then it loops back to the top of the menu which is what I want but then doesn't stop.
Also can you explain how I can import the code with the line numbers as I know this makes it easier for you to check the code
import sys
#history subject
def history():
print ('welcome to History Quiz')
print('Please choose a topic')
print ('1.WW1\n2.WW2\n3.Boer\n')
#first menu
invalidInput=True
def main():
print ("Please choose a subject")
print ("1. History")
print ("2. Computer Science")
print ("3. Quit")
choice = int(input("Please enter choice"))
if choice == 1:
history()
invalidInput=False
elif choice ==2:
print("Computer science")
invalidInput=False
elif choice == 3:
sys.exit()
invalidInput=False
else:
print("incorrect input. Enter 1-3")
while invalidInput:
main()
#Thank you
Sorry but copying the code into the window it has lost all the indents, if you can explain how to copy the code into the forum window without losing the indents I would be grateful
Thank you