Question

I am doing an assignment where I have to perform a quiz, and so far this is my code.

print("Hello and welcome to Shahaad's quiz!") #Introduction
name = input("What is your name? ")
print("Alright", name,", these will be today's topics:")
print("a) Video Games")
print("b) Soccer")
print("c) Geography") 
choice = input("Which topic would you like to begin with?")
if choice == 'video games'
    print("Lets start with Video Games!")

I am trying to make it that if the person chooses Video games as their first topic, it prints out the last line but I keep getting an error with the if choice == 'video games'.

Was it helpful?

Solution

Welcome to StackOverflow. You're so close!

You need a colon at the end of your if statement, like so:

if choice == 'video games':
    print("Lets start with Video Games!")

Anything in Python that opens a block: for loops, while loops, if statements, function definitions, and so on needs a colon after it.

But what if the user types in a different case (ViDeO GaMeS)? Let's convert it to lowercase to be sure.

if choice.lower() == 'video games':
    print("Let's start with Video Games!")

OTHER TIPS

As mentioned in the above answer you should use a colon. Besides, you are comparing to a wrong value: The user might type Video Games not video games or they may also type the whole choice: a) Video Games. So, you should always check to see if the selected words are in the input, not the whole or part of the word, like -

choice = "a) Video games"
if "Video games" in choice:
    print("You selected (a)")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top