Record#
- Continue learning about two-dimensional arrays.
- Use the append() function to add a row of data to the array.
- Use the remove() function to delete a row of data from the array.
- Today's exercise is to manipulate the Bingo card. The more we talk about it, the more knowledge we use in practice. It's beyond the scope. Hahaha!
CODE#
import random
bingo = []
def ran():
number = random.randint(1, 90)
return number
def prettyPrint():
for row in bingo:
for name in row:
print(f"{name: ^10}", end=" | ")
print()
print("--------------------------------------")
def numberinfo(n):
for i in range(len(bingo)):
for j in range(len(bingo[i])):
if n == bingo[i][j]:
bingo[i][j] = "x"
return 1
numbers = []
for i in range(8):
numbers.append(ran())
numbers.sort()
bingo = [[numbers[0], numbers[1],
numbers[2]], [numbers[3], "BINGO", numbers[4]],
[numbers[5], numbers[6], numbers[7]]]
numlist = 8
while True:
prettyPrint()
numkey = int(input("Next Number: "))
if numberinfo(numkey):
numlist = numlist - 1
if numlist == 0:
print("You Have Won")
break