Invalid syntax on single quotes
Question:
I’m working on a text adventure game and wanted to play a sound when you get a game over. I’m using PyGame to do this but it gives me an invalid syntax error on the last single quote when I try to load the sound file. here is the code:
import pygame
import time
pygame.mixer.pre_init(44100, 16, 2, 4096)
pygame.init()
snd_dir = path.join(path.dirname (_Dog-Walking-Simulator_) 'Game_Over_Yeah.wav')
Answers:
There’s a couple things wrong,
_Dog-Walking-Simulator_
is not a valid variable name (dashes aren’t allowed). But even if it were a valid variable name, it’s not defined. Perhaps you meant __file__
?
path
is not imported: from os import path
needs to be added to the imports at the top
- There’s no comma separating the parameters passed to
path.join
: path.join(path.dirname(__file__), 'Game_Over_Yeah.wav')
I’m working on a text adventure game and wanted to play a sound when you get a game over. I’m using PyGame to do this but it gives me an invalid syntax error on the last single quote when I try to load the sound file. here is the code:
import pygame
import time
pygame.mixer.pre_init(44100, 16, 2, 4096)
pygame.init()
snd_dir = path.join(path.dirname (_Dog-Walking-Simulator_) 'Game_Over_Yeah.wav')
There’s a couple things wrong,
_Dog-Walking-Simulator_
is not a valid variable name (dashes aren’t allowed). But even if it were a valid variable name, it’s not defined. Perhaps you meant__file__
?path
is not imported:from os import path
needs to be added to the imports at the top- There’s no comma separating the parameters passed to
path.join
:path.join(path.dirname(__file__), 'Game_Over_Yeah.wav')