二手产品经理

二手产品经理

THIS IS RENO

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

Record#

  1. Today I learned about two-dimensional arrays. The first dimension of a two-dimensional array is a list, and the second dimension contains the information within the list.
  2. For example: my2dlist = [["张三",20],["李四",28]]. Print: print (my2dlist [0]) = [["张三",20]]. print (my2dlist [0][0]) = 张三
  3. Edit the array: my2dlist [0][0] = "王五", print (my2dlist [0][0]) = 王五
  4. Today's exercise was to print a bingo card. I spent half an hour on it and couldn't figure it out. The correct answer in the end doesn't match the instructions. Maybe I overcomplicated it.

CODE#


import random

bingo = []

def ran():
  number = random.randint(1,90)
  return number

def prettyPrint():
  for row in bingo:
    print(row)

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]]
        ]

prettyPrint()

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