二手产品经理

二手产品经理

THIS IS RENO

2D Array - 44 Days - Learn Python Online in 100 Days

Record#

Catbox

  1. Continue learning about two-dimensional arrays.
  2. Use the append() function to add a row of data to the array.
  3. Use the remove() function to delete a row of data from the array.
  4. 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

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.