Back to Projects
Code Mission

My First Python Program

Build a quiz game that talks to the player, checks their answer, and keeps score. We are going code-first, so you can see exactly what each line does while you build it.

Easy1 hourprint(), input(), and if statements

What you'll build

A terminal quiz that asks a question, checks the answer, and shows the score.

Key concepts

Variables, strings, booleans, conditionals, and how code talks to humans.

Net Smart

Use school-approved coding sites and never type private information into your program. Names for practice are great. Passwords are not.
Live Terminal Preview
Running: python quiz_game.py

Welcome to the Math Quiz!

What is this?

This is known as the terminal! The terminal is where your code outputs. You can use commands like input() and print() to get stuff to show up there.
The Concept

Anatomy of a program: Input, logic, output.

A tiny quiz game is really a machine with three jobs. First it listens, then it thinks, then it responds.

Input

The player types something, and your program catches it with input().

answer = input("What is 2 + 2? ")

Logic

The program compares the answer and decides which path to take.

if answer == "4":

Output

The computer talks back with print() so the player sees what happened.

print("Correct!")

Warm-up

Setting the stage

Start by welcoming the player and making a score box that begins at zero.

Code snippetPython
1print("Welcome to the Math Quiz!")
2score = 0

Plain-English Explanation

Every game needs a starting point. This line tells the computer, 'Get ready, we are keeping track now.'

Deep Dive: Variables are memory boxes

When you write score = 0, Python builds a little storage spot named score. Later, you can open that box, change the number, and print the new result.

variablesfunctions

Input

Talking to the player

Ask the player for their name and their answer so the game feels alive.

Code snippetPython
1player_name = input("What is your name? ")
2answer = input("What is 2 + 2? ")

Plain-English Explanation

A quiz is boring if the computer only talks and never listens. input() turns your program into a conversation.

Pro Tip: input() always gives back text

Even if the player types 4, Python treats it as the string '4' until you change it. That is why beginners often compare answers to text first.

stringsfunctions

Logic

Making a decision

Use an if statement to ask, 'Did the player type the correct answer?'

Code snippetPython
1if answer == "4":
2 print("Correct!")
3else:
4 print("Not quite. Try again!")

Plain-English Explanation

This is the brain of the program. Without a decision, the computer cannot tell right from wrong.

Science of code: True or False

The test answer == '4' creates a boolean value. If it is True, Python runs the indented lines underneath the if. If it is False, Python jumps to else instead.

booleansconditionals

Points

Keeping score

When the answer is correct, add a point and show the player the new total.

Code snippetPython
1if answer == "4":
2 score = score + 1
3print("Your score is", score)

Plain-English Explanation

Games feel rewarding when something changes after a success. Updating score proves that variables can grow and change over time.

Deep Dive: score = score + 1

This line does not mean 'score is the same as score.' It means 'take the old number inside score, add 1, and store the new number back in the score box.'

variablesfunctions

Finale

Finishing with style

End the round with a personalized message so the game feels more polished.

Code snippetPython
1print(f"Thanks for playing, {player_name}!")
2print("Final score:", score)

Plain-English Explanation

Tiny details make beginner projects feel real. Personal messages show that code can mix stored information with text to create something new.

Pro Tip: f-strings are smart text

An f-string lets you slide variables directly into a message using curly braces. It is one of the nicest ways to make your code sound personal.

stringsvariables
Level Ups

Bonus missions that feel like game unlocks.

Once the basic quiz works, remix it. Great coders do not stop at "it runs." They ask what cool thing they can add next.

Bonus Mission

Level 1: The Time Traveler

Ask for the player's age

Make the quiz feel more personal by asking how old the player is before the first question.

age = input("How old are you? ")

Bonus Mission

Level 2: The Scorekeeper

Add easy and hard points

Give 1 point for easy questions and 5 points for hard ones so your quiz feels more game-like.

score = score + 5

Bonus Mission

Level 3: The Critic

Write a funny zero-point message

If the player gets zero points, make the program say something dramatic or silly.

if score == 0:
print("Even my calculator expected more.")

Want one more challenge? Add a second question and keep the same score variable alive all the way to the end. That is how your tiny script starts becoming a real game.