記錄#
- 繼續學習二維數組。
- 使用 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