Python Forum
Usborne Coding for Beginners using Python 'Dodge the Bombs' Syntax Error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Usborne Coding for Beginners using Python 'Dodge the Bombs' Syntax Error
#4
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:
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)
Reply


Messages In This Thread
RE: Usborne Coding for Beginners using Python 'Dodge the Bombs' Syntax Error - by Yokiya - Jun-18-2020, 05:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Database Submit Entry Syntax Error Melford 27 8,270 Jan-27-2020, 04:20 PM
Last Post: Denni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020