Folivao
Folivao

Reputation: 3

Code shows SyntaxError : multiple statements, but I don't know where the error is

my first ever question on Stack Overflow as I'm learning Python (with absolute no programming background whatsoever).

I'v tried finding an answer but I don't undestand where my error is. If the question is inappropriate I will delete it and I apologize.

I'm following a MOOC about Python. Very early, when learning about parameters and functions I came across an error I don't understand.

Here is the code, while running it it says "SyntaxError: multiple statements found while compiling a single statement"

# -*- coding: utf8 -*-
quotes = [
    "Hello !", 
    "Goodbye !"
]


characters = [
    "alvin et les Chipmunks", 
    "Babar", 
    "betty boop", 
    "calimero", 
    "casper", 
    "le chat potté", 
    "Kirikou"
]

user_answer == "B"

# Show random quote

If user_answer == "B":
  pass
elif user_answer == "C":
  print("Not the right answer !")
else:
  pass
  # show another quote

def show_random_quote(my_list):
    # get a random number
    quote = my_list[0]
    print(quote)

show_random_quote(quotes)

The full aim of the code would be to randomly show a quote and then randomly show a character.

For now only the quote must be shown.

I don't understand where my error is (and on the video, the teacher has the same exact code). I've tried with and without user_answer == "B" but it doesn't solve the problem. The increment seems alright.

I don't want to continue the lesson without understanding what I did wrong (I feel it's one of the best way to learn).

From what I understand : this block doesn't do anything as I have set the user_answer to B :

If user_answer == "B":
  pass
elif user_answer == "C":
  print("Not the right answer !")
else:
  pass

Only this function should make a quote appear : show_random_quote(quotes) as the function has been previously defind by def show_random_quote(my_list)

But I still don't understand.

Thanks in advance,

EDIT : Now I feel stupid for those 2 silly mistakes, thanks

Upvotes: 0

Views: 72

Answers (3)

Yama
Yama

Reputation: 9

The syntax error is in your first If.

You have to write keywords lower-case, so you have to write if instead of If.

Upvotes: 0

nagyl
nagyl

Reputation: 1644

You had a few simple errors like, If is if, if you define a variable you need to use = not ==.

Working code:

# -*- coding: utf8 -*-
quotes = [
    "Hello !", 
    "Goodbye !"
]


characters = [
    "alvin et les Chipmunks", 
    "Babar", 
    "betty boop", 
    "calimero", 
    "casper", 
    "le chat potté", 
    "Kirikou"
]

user_answer = "B"

# Show random quote

if user_answer == "B":
  pass
elif user_answer == "C":
  print("Not the right answer !")
else:
  pass
  # show another quote

def show_random_quote(my_list):
    # get a random number
    quote = my_list[0]
    print(quote)

show_random_quote(quotes)

Upvotes: 0

Andrej
Andrej

Reputation: 3235

When assign a value to a variable you have to use = not ==. Because == used for comparing two variables.
Replace user_answer == "B" with:

user_answer = "B"

Upvotes: 1

Related Questions