ritik
ritik

Reputation: 49

error with elif. says that elif is a syntax error

diamondCave = random.randint(1, 3)
    goldCave = random.randint(1, 3)
    while diamondCave == goldCave:
        goldCave = random.randint(1, 3)

    if chosenCave == str(diamondCave):
    pygame.mixer.init()
pygame.mixer.music.load("test.wav")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
    continue
    print('full of diamonds!')
elif: chosenCave == str(goldCave):
    print('full of gold!')
else:
        print('hungry and gobbles you down in one bite!')
playAgain = 'yes'
while playAgain == 'yes' or playAgain == 'y':

    displayIntro ()

    caveNumber = chooseCave()

    checkCave(caveNumber)

    print('Do you want to play again? (yes or no)')
    playAgain = input()
else:
        pygame.mixer.init()
pygame.mixer.music.load("test.wav")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
    continue

I want to make the code so that each time a chest is picked, it plays a sound. When a diamond gets picked it makes a cool sound, when gold is picked, a different sound is played, and when the chest eats you, it should make a game over sound. Every time I use the code of the sound, it says that the elif statement is invalid syntax. What did I do wrong?

Upvotes: 0

Views: 93

Answers (2)

SebasSBM
SebasSBM

Reputation: 908

Remove the ":" after the elif

elif: chosenCave == str(goldCave):

Like this:

elif chosenCave == str(goldCave):

Upvotes: 2

abarnert
abarnert

Reputation: 365597

The problem is that elif: is a syntax error.

The whole point of elif is that it means else if. Just like you can't write if: without a condition, you can't write elif: without a condition.

Meanwhile, the statement after the : is clearly supposed to be the condition expression, not a statement. So you almost certainly wanted this:

elif chosenCave == str(goldCave):

Upvotes: 3

Related Questions