記錄#
- 今天學習二維陣列。二維陣列的第一維是 list,第二維才是 list 內的資訊。
- 例如:my2dlist=[["張三",20],["李四",28]]。打印: print (my2dlist [0])=[["張三",20]。print (my2dlist [0][0])= 張三
- 編輯陣列:my2dlist [0][0] = "王五",print (my2dlist [0][0])= 王五
- 今天的練習是打印 bing card ,寫了半個小時沒搞定,最後的正確答案按題目講也不對。可能是我想太複雜了。
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()