记录#
- 继续学习二维数组。
- 使用 append () 函数向数组中添加一行数据。
- 使用.remove () 函数在数组中删除一行数据。
- 今天的练习是对 Bingo 卡进行操作,讲的越多,练习中用到的知识就越多了。超纲了。哈哈哈!
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