import random
print("Bingo Card Generator")
BingoNumbers = random.sample(range(1, 91), 9)
BingoNumbers.sort()
Bingo = [
[BingoNumbers[0]],
[BingoNumbers[1]],
[BingoNumbers[2]],
[BingoNumbers[3]],
["BINGO"],
[BingoNumbers[4]],
[BingoNumbers[5]],
[BingoNumbers[6]],
[BingoNumbers[7]],
]
def CreateCard():
for row in Bingo:
print(*row, end="\t|\t")
print()
CreateCard()
num = int(input("Next Number: "))
exes = 0
for row in range(3):
for item in range(3):
if Bingo[row][item] == num:
Bingo[row][item] = "X"
for row in Bingo:
for item in row:
if item == "X":
exes += 1
if exes == 8:
print("You have won!")
else:
print("You have Lost")
Ok, I think I figured this one out. There was a lot of odd stuff going on within the loops and in your initial list, and I believe it is all fixed now.
I also fixed your Bingo print layout, so it lists in its proper rows now, and it also clears the console for a more pleasing view.
from replit import clear
import random
BingoNumbers = random.sample(range(1, 91), 9)
BingoNumbers.sort()
Bingo = [[BingoNumbers[0], BingoNumbers[1], BingoNumbers[2]],
[BingoNumbers[3], "BINGO", BingoNumbers[4]],
[BingoNumbers[5], BingoNumbers[6], BingoNumbers[7]]]
def CreateCard():
print("Bingo Card Generator\n")
for row in Bingo:
for item in row:
print(item, end="\t|\t")
print("\n")
att = 0
exes = 0
while att < 8:
CreateCard()
num = int(input("Next Number: "))
for row in range(3):
for item in range(3):
if Bingo[row][item] == num:
Bingo[row][item] = "X"
exes += 1
att += 1
clear()
CreateCard()
if exes == 8:
print("You have won!")
else:
print("You have Lost")
Hope this fixes your problem!
2 Likes
so a loop problem ahh well it helped thank you so much.
1 Like
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.