Jun-18-2020, 05:55 PM
Hi CMSheWolfe,
I am also using the book to learn how to code, and got stuck with the "printfield" function. I wonder if it is what is causing you trouble too, so here is what I did to make it work:
- Also, for it to work you need to call the create_bombfield function, so I have added that above the printfield function call.
- If this works ok and is showing you the "map of bombs" in your shell, you can add the # sign in front of the two function calls so they become comments and are not run with the rest of the programme...
I am also using the book to learn how to code, and got stuck with the "printfield" function. I wonder if it is what is causing you trouble too, so here is what I did to make it work:
import tkinter import random gameOver = False score = 0 squaresToClear = 0 def play_bombdodger(): create_bombfield(bombfield) window = tkinter.Tk() layout_window(window) window.mainloop() bombfield = [] def create_bombfield(bombfield): global squaresToClear for row in range(0,10): rowList = [] for column in range(0,10): if random.randint(1,100) < 20: rowList.append(1) else: rowList.append(0) squaresToClear = squaresToClear + 1 bombfield.append(rowList) def printfield(bombfield): for rowList in bombfield: print(rowList) create_bombfield(bombfield) printfield(bombfield)- From what I can understand, you can't call a function if you didn't define it beforehand. So I put the "printfield(bombfield)" line under the function definition.
- Also, for it to work you need to call the create_bombfield function, so I have added that above the printfield function call.
- If this works ok and is showing you the "map of bombs" in your shell, you can add the # sign in front of the two function calls so they become comments and are not run with the rest of the programme...
#create_bombfield(bombfield) #printfield(bombfield)