Python Python Collections (2016, retired 2019) Dungeon Game Cartographer

Error: invalid syntax

Hi everyone,

I have the exact same code as the teacher and when I try to run, I get a syntax error from this bit of code (it's the last line of code inside the draw_map function): print(output, end=line_end)

The error I'm getting is (it's pointing to the equal sign): print(output, end=line_end) ^ SyntaxError: invalid syntax

Any ideas why this is happening ?

Thank you!

2 Answers

Steven Parker
Steven Parker
182,438 Points

Sometimes the point where the system determined there was an error isn't the place where the error actually is. The actual issue could be related to indentation or something on a previous line.

This is one of the reasons it's always good to show the complete code, with proper formatting, to facilitate the most specific answers. Even better, make a snapshot of your workspace and post the link to it here.

Hi, thank you for being so quick replying!

I'm using visual studio code, here's my code:

import os
import random

CELLS = [(0,0), (1,0), (2,0), (3,0), (4,0),
         (0,1), (1,1), (2,1), (3,1), (4,1),
         (0,2), (1,2), (2,2), (3,2), (4,2),
         (0,3), (1,3), (2,3), (3,3), (4,3),
         (0,4), (1,4), (2,4), (3,4), (4,4)]

# This will look like:
#  Y
#  _  _ _ _ _
#  0 |_|_|_|#|
#  1 |_|_|_|_|
#  2 |_|_|_|_|
#  3 |_|_|_|_|
#     0 1 2 3 | X

def clear_screen():
    os.system('cls' if == "nt" else "clear")

def get_locations():
    return random.sample(CELLS, 3)

def move_player(player, move):
    x, y = player
    if move == "LEFT":
        x -= 1
    if move == "RIGHT":
        x += 1
    if move == "UP":
        y -= 1
    if move == "DOWN":
        y += 1
    return x,y

def get_moves(player):
    moves = ["LEFT", "RIGHT", "UP", "DOWN"]
    x, y = player

    if x==0:
    if x==4:
    if y==0:
    if y==4:
    return moves

def draw_map(player):
    print(" _"*5)
    tile = "|{}"

    for cell in CELLS:
        x, y = cell
        if x < 4:
            line_end = ""
            if cell == player:
                output = title.format("x")
                output = title.format("_")
            line_end = "\n"
            if cell == player:
                output = title.format("X|")
                output = title.format("_|")
        print(output, end=line_end)

def game_loop():
    monster, door, player = get_locations()

    while True:
        valid_moves = get_moves(player)

        print("You're currently in room {}".format(player)) #fill with player position
        print("You can move {}".format(", ".join(valid_moves))) #fill with available moves
        print("Enter QUIT to quit")

        move = input("> ").upper

        if move == "QUIT":
        if move in valid_moves:
            player = move_player(player, move)
            input("\n ** Walls are hard! Don't run into them **\n")

print("Welcome to The Dungeon!")
input("Press return to start")

Hello again, I found that I'm using python 2.* version, and that does not accept that end in the print statement. I have replaced for:

print(output % line_end)
Steven Parker
Steven Parker
182,438 Points

You should definitely update your Python! All of the courses here use Python 3.

It also looks like you have several references to an undefined "title" in that function. I suspect you meant "tile" instead.

That should take care of syntax issues. You may still have some function bugs to work out.

Hi Steven, yes, I realised that tile/title mistake and have some bugs to solve because is still not working properly.

Will update my python. Thanks!