I have this working code for a bingo-like game in Python (a winner is announced when the full card is matched):
bingoCard = [7, 26, 40, 58, 73, 14, 22, 34, 55, 68]
while len(bingoCard) != 0:
nNumberCalled = int(input("\nPlease enter the announced Bingo Number: "))
if nNumberCalled <1 or nNumberCalled > 80:
print("Oops, the number should be between 1 and 80.")
elif nNumberCalled in bingoCard:
bingoCard.remove(nNumberCalled)
print(f"Nice on1e! You hit {nNumberCalled}.")
else:
print("Nah... Not in your card.")
print("\nBINGO!!!")
The idea is that I remove numbers from the bingoCard
as they are called, until the list is empty.
I would like to give to the user the option to quit the game (break out of the loop) at any time by typing "quit".
I tried to research this question, but I couldn't figure out how or where to add a break
statement into my code to make it work correctly. I guess I have to include something else such as try
/except
or maybe a for
loop inside the while
loop. How do I make this work?