Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loop continuous
#1
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
Reply
#2
See BBcode help for copying code.

def main():
  global invalidInput
  ...
  ...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: Unknown label type: 'continuous-multioutput' hobbyist 7 1,280 Sep-13-2023, 05:41 PM
Last Post: deanhystad
  Extract continuous numeric characters from a string in Python Robotguy 2 2,630 Jan-16-2021, 12:44 AM
Last Post: snippsat
  How to get continuous movement whilst using State Machine cjoe1993 2 1,818 Dec-10-2020, 06:36 AM
Last Post: cjoe1993

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020