Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
โ† Python Fundamentals Level One ยท Lesson 4 of 5

Module Three

๐Ÿ“– Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
4
Module 3 ยท Python Programming Level 1

๐Ÿ Module Three: Building Cool Projects โ€“ Strings, Tuples, and More!

1. Module Title

Module Three: Building Cool Projects โ€“ Strings, Tuples, and More!


2. Module Introduction

Welcome back, young coder! You have made incredible progress. In Module One, you learned the basics โ€“ variables, data types, input, if/else, loops, lists, and functions. In Module Two, you explored dictionaries, sets, file handling, error handling, functions with return values, and even classes!

Now, in Module Three, we will learn some new, powerful concepts that will make your code even better. We will explore strings in more detail โ€“ they are not just text, they have many cool methods! We will learn about tuples โ€“ a special kind of list that cannot be changed. We will discover how to pack and unpack values. We will build a real game โ€“ a "Millionaire Quiz Game" โ€“ using everything we have learned. We will also learn some advanced function tricks like default arguments and keyword arguments.

This module is all about taking your skills to the next level and building something fun. Let's get started!


3. Learning Objectives

After completing this module, you will be able to:

  • Use string methods to manipulate text (lower, upper, split, join, etc.).
  • Understand and use tuples โ€“ immutable lists.
  • Pack and unpack values in Python.
  • Use default arguments in functions.
  • Use keyword arguments in functions.
  • Build a complete "Millionaire Quiz Game" project.
  • Combine all your Python skills in a real-world project.
  • Write clean, well-documented code.

4. Warm-up Story

Chidi's Millionaire Dream

Chidi loved watching the TV show "Who Wants to Be a Millionaire?" He always dreamed of being a contestant. He said to his friend Ada, "I wish I could practice with questions before the show!" Ada said, "Chidi, you know Python! You can build your own quiz game!"

Chidi was excited. He decided to build a "Millionaire Quiz Game" using Python. He created a list of questions and answers. He used strings to format the questions nicely. He used loops to go through all the questions. He used if/else to check if the answers were correct. He even used a dictionary to keep track of scores. When he finished, he had a fully working game. He invited his friends to play, and they all had fun. Chidi realised that with Python, he could build anything he imagined!


5. Main Lessons

Lesson 1: Review of Modules One and Two

Before we start new things, let's quickly review what we learned in the first two modules.

From Module One:

  • Variables store data.
  • Data types: integers, floats, strings.
  • input() gets user input.
  • if/elif/else for decisions.
  • while and for loops.
  • Lists store many items.
  • Functions with def.
  • Comments with #.

From Module Two:

  • Dictionaries store key-value pairs.
  • Sets store unique items.
  • Reading and writing files.
  • Error handling with try/except.
  • Functions with parameters and return values.
  • Classes and objects.
  • List methods like append(), sort(), reverse().

You have a strong foundation. Now, let's add some more tools to your toolbox!


Lesson 2: String Methods โ€“ Making Text Smarter

Definition: Strings are pieces of text. Python has many built-in methods (tools) that let you change and work with strings.

Why it's important: You will often need to clean, format, or change text in your programs.

Simple explanation: It's like having a set of tools to fix, clean, and change words.

Real-life example: Changing all letters to uppercase for a consistent look.

School example: Removing extra spaces from a student's name.

Home example: Checking if a password is strong.

Nigerian example: Formatting a phone number to a standard format.

Illustration โ€“ Code:

  # String methods
  text = "   Hello, World!   "

  # Remove extra spaces from the ends
  print(text.strip())  # "Hello, World!"

  # Convert to uppercase
  print(text.upper())  # "   HELLO, WORLD!   "

  # Convert to lowercase
  print(text.lower())  # "   hello, world!   "

  # Split into a list of words
  words = text.split()  # ["Hello,", "World!"]

  # Check if it starts with something
  print(text.startswith(" Hello"))  # True

  # Check if it ends with something
  print(text.endswith("!"))  # True

  # Find a word
  print(text.find("World"))  # Finds the position

  # Replace text
  print(text.replace("World", "Python"))  # "   Hello, Python!   "

Mini summary: String methods let you manipulate and work with text easily.


Lesson 3: More String Methods โ€“ Formatting and Joining

Definition: We can format strings using format() or f-strings. We can also join strings together from a list.

Why it's important: Formatting helps you create nice-looking output. Joining helps you combine many pieces of text.

Simple explanation: It's like putting puzzle pieces together to make a complete picture.

Real-life example: Creating a sentence from a list of words.

School example: Printing a report card with formatted grades.

Home example: Creating a shopping list with prices.

Nigerian example: Formatting currency values with the Naira symbol.

Illustration โ€“ Code:

  # Using f-strings (preferred in modern Python)
  name = "Ada"
  age = 10
  print(f"Hello, {name}! You are {age} years old.")

  # Using format() method
  print("Hello, {}! You are {} years old.".format(name, age))

  # Joining a list of strings
  words = ["Python", "is", "awesome"]
  sentence = " ".join(words)
  print(sentence)  # "Python is awesome"

  # Splitting a string into a list
  text = "apple,banana,mango"
  fruits = text.split(",")
  print(fruits)  # ["apple", "banana", "mango"]

Mini summary: format() and f-strings format text; join() combines strings.


Lesson 4: What is a Tuple?

Definition: A tuple is like a list, but it cannot be changed (it is immutable). You create a tuple using parentheses ().

Why it's important: Tuples are used for data that should not change โ€“ like days of the week, coordinates, or settings.

Simple explanation: A tuple is like a list that you write in pen โ€“ you can't erase or change it.

Real-life example: The days of the week: ("Monday", "Tuesday", "Wednesday").

School example: The subjects in a school timetable.

Home example: The names of your family members.

Nigerian example: The names of the states in the South-East.

Illustration โ€“ Code:

  # Creating a tuple
  days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")

  # Accessing items
  print(days[0])  # "Monday"

  # Looping through a tuple
  for day in days:
      print(day)

  # Trying to change a tuple will cause an error
  # days[0] = "Sunday"  # Error! Tuples cannot be changed

Mini summary: Tuples are like lists, but they cannot be changed after creation.


Lesson 5: Packing and Unpacking

Definition: Packing is putting multiple values into a tuple. Unpacking is taking those values out and assigning them to variables.

Why it's important: Packing and unpacking make it easy to work with multiple values at once.

Simple explanation: It's like packing a suitcase (packing) and then unpacking it when you arrive (unpacking).

Real-life example: Returning multiple values from a function.

School example: Getting a student's name, age, and grade in one go.

Home example: Getting the temperature, humidity, and wind speed from a weather sensor.

Nigerian example: Getting the name, price, and quantity of a product from a database.

Illustration โ€“ Code:

  # Packing values into a tuple
  student = ("Ada", 10, "A")

  # Unpacking values into variables
  name, age, grade = student
  print(name)   # "Ada"
  print(age)    # 10
  print(grade)  # "A"

  # Returning multiple values from a function
  def get_student():
      return "Chidi", 12, "B"

  name2, age2, grade2 = get_student()
  print(name2, age2, grade2)  # "Chidi 12 B"

  # Swapping values using tuple unpacking
  a = 5
  b = 10
  a, b = b, a
  print(a, b)  # 10 5

Mini summary: Packing groups values; unpacking separates them into variables.


Lesson 6: Default Arguments in Functions

Definition: Default arguments let you set a default value for a parameter. If the caller doesn't provide a value, the default is used.

Why it's important: Default arguments make your functions more flexible and easier to use.

Simple explanation: It's like having a backup plan โ€“ if the user doesn't choose, you decide for them.

Real-life example: A function that greets a person. If no name is given, it says "Hello, Guest!".

School example: A function that calculates grades. If no pass mark is given, it uses 50 as default.

Home example: A function that calculates a discount. If no discount is given, it uses 10% as default.

Nigerian example: A function that calculates tax. If no tax rate is given, it uses 7.5% as default.

Illustration โ€“ Code:

  # A function with a default argument
  def greet(name="Guest"):
      print("Hello, " + name + "!")

  greet()          # Prints: Hello, Guest!
  greet("Ada")     # Prints: Hello, Ada!

  # Another example
  def calculate_discount(price, discount=10):
      return price - (price * discount / 100)

  print(calculate_discount(100))     # Uses 10% discount -> 90
  print(calculate_discount(100, 20)) # Uses 20% discount -> 80

Mini summary: Default arguments give a fallback value if the user doesn't provide one.


Lesson 7: Keyword Arguments in Functions

Definition: Keyword arguments let you pass arguments to a function by name, not just by position. This makes your code clearer.

Why it's important: It makes function calls easier to read and understand.

Simple explanation: It's like saying "Put the sugar in the bowl" โ€“ you name what you are doing.

Real-life example: order(food="Pizza", quantity=2).

School example: grade(student="Ada", score=90).

Home example: set_alarm(time="7:00", days="Monday").

Nigerian example: buy_item(name="Rice", quantity=5, price=1000).

Illustration โ€“ Code:

  # A function with multiple parameters
  def student_info(name, age, grade):
      print(f"Name: {name}, Age: {age}, Grade: {grade}")

  # Positional arguments (order matters)
  student_info("Ada", 10, "A")

  # Keyword arguments (order doesn't matter)
  student_info(grade="B", name="Chidi", age=12)

  # Mixing positional and keyword (positional first)
  student_info("Bola", age=11, grade="C")

  # Default arguments with keyword arguments
  def greet(name="Guest", greeting="Hello"):
      print(greeting + ", " + name + "!")

  greet()                          # Hello, Guest!
  greet(name="Ada")                # Hello, Ada!
  greet(greeting="Hi", name="Chidi") # Hi, Chidi!

Mini summary: Keyword arguments let you pass values by name for clarity.


Lesson 8: The Power of len() and range()

Definition: len() returns the length (number of items) of a collection. range() generates a sequence of numbers.

Why it's important: They are used in loops and to check sizes of data structures.

Simple explanation: len() counts how many, range() gives you numbers to count with.

Real-life example: Checking the length of a password.

School example: Looping through a list of student names.

Home example: Creating a range of numbers for a timer.

Nigerian example: Counting the number of items in a shopping list.

Illustration โ€“ Code:

  # len() โ€“ get the length
  fruits = ["Mango", "Orange", "Banana"]
  print(len(fruits))  # 3

  text = "Hello, World!"
  print(len(text))    # 13

  # range() โ€“ generate numbers
  for i in range(5):
      print(i)  # Prints 0, 1, 2, 3, 4

  # range(start, stop, step)
  for i in range(1, 10, 2):
      print(i)  # Prints 1, 3, 5, 7, 9

  # Using len() and range() together
  for i in range(len(fruits)):
      print(fruits[i])

Mini summary: len() counts items; range() generates number sequences.


Lesson 9: List Comprehensions โ€“ A Shorter Way to Build Lists

Definition: List comprehensions are a shorter way to create lists. They combine a loop and a condition in one line.

Why it's important: They make your code shorter and easier to read.

Simple explanation: It's like writing a loop and an if statement all in one line.

Real-life example: Creating a list of doubled numbers.

School example: Creating a list of even numbers from 1 to 20.

Home example: Creating a list of words that start with "a".

Nigerian example: Creating a list of prices above a certain amount.

Illustration โ€“ Code:

  # Traditional way
  squares = []
  for i in range(1, 6):
      squares.append(i * i)
  print(squares)  # [1, 4, 9, 16, 25]

  # List comprehension โ€“ shorter!
  squares2 = [i * i for i in range(1, 6)]
  print(squares2)  # [1, 4, 9, 16, 25]

  # With a condition
  evens = [i for i in range(1, 11) if i % 2 == 0]
  print(evens)  # [2, 4, 6, 8, 10]

  # Using with strings
  fruits = ["Mango", "Orange", "Banana"]
  upper_fruits = [fruit.upper() for fruit in fruits]
  print(upper_fruits)  # ["MANGO", "ORANGE", "BANANA"]

Mini summary: List comprehensions are a shorter way to create lists from loops.


Lesson 10: Building the Millionaire Quiz Game โ€“ Planning

Now we will build our capstone project โ€“ a "Millionaire Quiz Game". Let's plan it first.

What the game will do:

  1. Show the user questions one by one.
  2. Each question has 4 answer choices (A, B, C, D).
  3. The user selects an answer.
  4. The game checks if the answer is correct.
  5. If correct, the user earns points.
  6. If wrong, the game ends or shows the correct answer.
  7. The game displays the final score at the end.

What we need:

  • Questions and answers stored in a data structure (list of tuples).
  • A loop to go through all questions.
  • User input to get the answer.
  • Conditional statements to check answers.
  • A score counter.
  • String formatting to display questions and options nicely.

Lesson 11: Building the Millionaire Quiz Game โ€“ Step 1: Data

We will store our questions in a list of tuples. Each tuple will have: (question, option_a, option_b, option_c, option_d, correct_answer).

Illustration โ€“ Code:

  # List of questions
  questions = [
      ("What is the capital of Nigeria?", "Lagos", "Abuja", "Kano", "Ibadan", "B"),
      ("Who is the president of Nigeria?", "Buhari", "Tinubu", "Jonathan", "Obasanjo", "B"),
      ("What is 5 + 3?", "6", "7", "8", "9", "C"),
      ("Which is the largest country in Africa?", "Nigeria", "South Africa", "Algeria", "DR Congo", "C"),
      ("What is the currency of Nigeria?", "Naira", "Cedis", "Rand", "Shilling", "A")
  ]

Mini summary: Store questions in a list of tuples for easy access.


Lesson 12: Building the Millionaire Quiz Game โ€“ Step 2: Display and Check

We will write a function to display a question and its options, get user input, and check if it's correct.

Illustration โ€“ Code:

  def ask_question(question_tuple):
      # Unpack the tuple
      question, a, b, c, d, correct = question_tuple

      # Display the question and options
      print("\n" + question)
      print("A. " + a)
      print("B. " + b)
      print("C. " + c)
      print("D. " + d)

      # Get user's answer
      answer = input("Your answer (A/B/C/D): ").upper()

      # Check if correct
      if answer == correct:
          print("โœ… Correct!")
          return True
      else:
          print("โŒ Wrong! The correct answer was " + correct + ".")
          return False

Mini summary: Display the question, get input, and check the answer.


Lesson 13: Building the Millionaire Quiz Game โ€“ Step 3: The Main Game Loop

Now we put everything together with a main game loop.

Illustration โ€“ Code:

  def play_game():
      score = 0
      total = len(questions)

      print("=" * 40)
      print("๐ŸŽ‰ WELCOME TO THE MILLIONAIRE QUIZ GAME! ๐ŸŽ‰")
      print("=" * 40)

      for index, q in enumerate(questions):
          print(f"\n๐Ÿ“Œ Question {index + 1} of {total}")
          if ask_question(q):
              score += 1

      # Display final score
      print("\n" + "=" * 40)
      print(f"๐Ÿ† GAME OVER! You scored {score} out of {total}.")
      if score == total:
          print("๐ŸŽ‰ PERFECT SCORE! You are a genius! ๐ŸŽ‰")
      elif score >= total * 0.7:
          print("๐ŸŒŸ Great job! You are a quiz master!")
      elif score >= total * 0.4:
          print("๐Ÿ‘ Not bad! Keep learning!")
      else:
          print("๐Ÿ“š Keep studying! You'll do better next time!")
      print("=" * 40)

  # Run the game
  play_game()

Mini summary: The main loop runs all questions and displays the final score.


Lesson 14: Enhancing the Quiz Game โ€“ Adding Difficulty Levels

We can add difficulty levels to our game. Easy questions, medium questions, and hard questions.

Illustration โ€“ Code:

  # Questions with difficulty
  easy_questions = [
      ("What is the capital of Nigeria?", "Lagos", "Abuja", "Kano", "Ibadan", "B"),
      ("What is 5 + 3?", "6", "7", "8", "9", "C")
  ]

  medium_questions = [
      ("Which year did Nigeria gain independence?", "1950", "1960", "1970", "1980", "B"),
      ("Who is the current president of Nigeria?", "Buhari", "Tinubu", "Jonathan", "Obasanjo", "B")
  ]

  hard_questions = [
      ("What is the largest state in Nigeria by area?", "Lagos", "Borno", "Niger", "Bauchi", "C"),
      ("Which river is the longest in Nigeria?", "Niger", "Benue", "Cross", "Ogun", "A")
  ]

  def play_with_difficulty():
      difficulty = input("Choose difficulty (easy/medium/hard): ").lower()
      if difficulty == "easy":
          questions = easy_questions
      elif difficulty == "medium":
          questions = medium_questions
      elif difficulty == "hard":
          questions = hard_questions
      else:
          print("Invalid choice. Playing easy mode.")
          questions = easy_questions

      # Play the game with the chosen questions...

Mini summary: Add difficulty levels to make the game more interesting.


Lesson 15: Review โ€“ What We Learned in Module Three

In this module, we learned:

  • String methods โ€“ how to manipulate text.
  • Tuples โ€“ immutable lists.
  • Packing and unpacking values.
  • Default arguments and keyword arguments in functions.
  • The power of len() and range().
  • List comprehensions โ€“ a shorter way to build lists.
  • How to build a complete "Millionaire Quiz Game" project.
  • How to add difficulty levels to a game.

You now have the skills to build real projects with Python!


6. Key Vocabulary

  • String Method: A function that works on strings (like upper(), lower()).
  • Tuple: An immutable list (cannot be changed).
  • Packing: Putting multiple values into a tuple.
  • Unpacking: Taking values out of a tuple.
  • Default Argument: A parameter with a default value.
  • Keyword Argument: Passing arguments by name.
  • List Comprehension: A shorter way to create lists.
  • Immutable: Cannot be changed.

7. Important Concepts

  • String methods make text processing easy: You can clean, format, and change text.
  • Tuples protect data: Use them when you don't want data to change.
  • Packing and unpacking are powerful: They make it easy to work with multiple values.
  • Default and keyword arguments make functions flexible: They are easier to use.
  • List comprehensions are concise: They make your code shorter.
  • Building projects is the best way to learn: Apply everything you know.

8. Step-by-step Explanations

How to build a quiz game:

  1. Plan your questions and store them in a data structure.
  2. Write a function to display a question and get the answer.
  3. Write the main game loop that goes through all questions.
  4. Keep track of the score.
  5. Display the final score and a message.
  6. Enhance with difficulty levels, timers, or other features.

9. Real-life Examples

  • A quiz app on a phone.
  • A game show like "Who Wants to Be a Millionaire?"
  • A school test with multiple-choice questions.
  • An online survey with questions.
  • A trivia night at a bar or restaurant.

10. Nigerian Examples

  • A quiz game about Nigerian history and culture.
  • A trivia app for Nigerian students.
  • A game about Nigerian states and capitals.
  • A quiz about Nigerian celebrities.
  • A learning app for Nigerian children.

11. Fun Examples Children Can Relate To

  • A quiz about favourite cartoons.
  • A game about animals and their sounds.
  • A trivia game about video games.
  • A quiz about popular movies.
  • A game about school subjects.

12. Everyday Examples

  • ๐Ÿ“ฑ A mobile quiz app.
  • ๐ŸŽฎ A game show on TV.
  • ๐Ÿ“ A school test.
  • ๐Ÿ“Š A survey with multiple-choice questions.
  • ๐ŸŽฏ A trivia night with friends.

13. Teacher Notes

This module is project-focused. Let students work on the quiz game step by step. Encourage them to add their own features โ€“ more questions, difficulty levels, timers, or graphics. Pair programming works well here.


14. Parent Tips

Play the quiz game with your child! Let them quiz you on the questions they created. Encourage them to add more questions from subjects they enjoy. Celebrate their achievement in building a complete game!


15. Interesting Facts

  • ๐ŸŽฎ The first video game was created in 1958!
  • ๐Ÿ“Š "Who Wants to Be a Millionaire?" first aired in 1999.
  • ๐Ÿง  The average human can remember about 7 things at once.
  • ๐Ÿ’ป Python was named after Monty Python, not the snake.
  • ๐Ÿ† Some people have won real million-dollar prizes on quiz shows!

16. Did You Know?

  • You can build a quiz game with just a few lines of Python!
  • Many online learning platforms use quiz games to teach.
  • Quiz games are a great way to study for tests.
  • You can add a timer to make the game more exciting.
  • You can store questions in a file to make the game longer.

17. Remember This

  • โœ… Strings have many useful methods.
  • โœ… Tuples cannot be changed.
  • โœ… Packing and unpacking are powerful.
  • โœ… Default and keyword arguments make functions flexible.
  • โœ… List comprehensions make code shorter.
  • โœ… Building projects is the best way to learn.

18. Common Mistakes

  • โŒ Trying to change a tuple โ€“ remember, tuples are immutable!
  • โŒ Forgetting to convert user input to the correct format.
  • โŒ Not handling when the user enters an invalid choice.
  • โŒ Forgetting to check the length of strings before accessing characters.
  • โŒ Using a list comprehension that is too complex to read.

19. Best Practices

  • โœ… Use tuples for data that shouldn't change.
  • โœ… Use string methods to clean and format text.
  • โœ… Use default and keyword arguments for clarity.
  • โœ… Use list comprehensions for simple transformations.
  • โœ… Always test your code with different inputs.

20. Illustrations

Quiz Game Flowchart

  +-------------+     +-------------+     +-------------+     +-------------+
  |  START      | --> |  SHOW       | --> |  GET        | --> |  CHECK      |
  |  GAME       |     |  QUESTION   |     |  USER       |     |  ANSWER     |
  +-------------+     +-------------+     |  INPUT      |     +-------------+
                                  |       +-------------+           |
                                  |                            +-------------+
                                  |                            |  CORRECT?   |
                                  |                            +-------------+
                                  |                            |       |
                                  |                            V       V
                                  |                      +-------------+   +-------------+
                                  |                      |  SCORE++    |   |  SHOW       |
                                  |                      +-------------+   |  CORRECT    |
                                  |                                       |  ANSWER     |
                                  V                                       +-------------+
                          +-------------+                                       |
                          |  MORE       | <------------------------------------+
                          |  QUESTIONS? |
                          +-------------+
                                | Yes
                                V
                          +-------------+
                          |  FINAL      |
                          |  SCORE      |
                          +-------------+
                                V
                          +-------------+
                          |  END GAME   |
                          +-------------+

Comparison Table โ€“ Data Structures

Data StructureOrderedMutableAllows DuplicatesExample
ListYesYesYes[1, 2, 3, 3]
TupleYesNoYes(1, 2, 3, 3)
SetNoYesNo{1, 2, 3}
DictionaryYes (Python 3.7+)YesKeys: No, Values: Yes{"a": 1, "b": 2}

Comparison Table โ€“ String Methods

MethodWhat It DoesExample
upper()Converts to uppercase"hello".upper() โ†’ "HELLO"
lower()Converts to lowercase"HELLO".lower() โ†’ "hello"
strip()Removes spaces from ends" hi ".strip() โ†’ "hi"
split()Splits into a list"a,b,c".split(",") โ†’ ["a","b","c"]
join()Joins a list into a string",".join(["a","b"]) โ†’ "a,b"
replace()Replaces text"hi".replace("i","o") โ†’ "ho"

Timeline โ€“ Module Three Learning Path

  +------------------------------------------------------------------+
  |  Lesson 1: Review of Modules One and Two                         |
  |  Lesson 2: String Methods โ€“ Making Text Smarter                  |
  |  Lesson 3: More String Methods โ€“ Formatting and Joining          |
  |  Lesson 4: What is a Tuple?                                      |
  |  Lesson 5: Packing and Unpacking                                 |
  |  Lesson 6: Default Arguments in Functions                        |
  |  Lesson 7: Keyword Arguments in Functions                        |
  |  Lesson 8: The Power of len() and range()                        |
  |  Lesson 9: List Comprehensions โ€“ A Shorter Way to Build Lists    |
  |  Lesson 10: Building the Millionaire Quiz Game โ€“ Planning        |
  |  Lesson 11: Building the Millionaire Quiz Game โ€“ Step 1: Data   |
  |  Lesson 12: Building the Millionaire Quiz Game โ€“ Step 2: Display |
  |  Lesson 13: Building the Millionaire Quiz Game โ€“ Step 3: Main   |
  |  Lesson 14: Enhancing the Quiz Game โ€“ Adding Difficulty Levels   |
  |  Lesson 15: Review                                               |
  +------------------------------------------------------------------+

23. End-of-Module Summary

In this module, we have taken our Python skills to a new level. We learned powerful string methods that let us manipulate text easily. We discovered tuples โ€“ immutable lists that protect our data from being changed. We mastered packing and unpacking, which makes working with multiple values a breeze. We learned about default and keyword arguments, which make our functions more flexible and our code clearer.

We explored len() and range(), two essential tools for loops. We learned about list comprehensions โ€“ a shorter, more elegant way to build lists. Most importantly, we built a complete "Millionaire Quiz Game" project that used everything we learned. We even added difficulty levels to make it more interesting.

You now have the confidence and skills to build real projects with Python. You can create games, apps, and tools that solve problems and entertain people. The journey continues โ€“ keep coding, keep exploring, and keep having fun!


24. Frequently Asked Questions

  1. What are string methods? Functions that work on strings, like upper() and lower().
  2. What is a tuple? A list that cannot be changed.
  3. What is packing and unpacking? Packing groups values; unpacking separates them.
  4. What is a default argument? A parameter with a default value if not provided.
  5. What is a keyword argument? Passing arguments by name.
  6. What does len() do? Returns the length of a collection.
  7. What does range() do? Generates a sequence of numbers.
  8. What is a list comprehension? A shorter way to create lists.
  9. What is the best way to learn Python? Build projects!
  10. Can I make games with Python? Yes! You just built a quiz game.

25. Review Questions

  1. What does upper() do?
  2. What does split() do?
  3. What is the difference between a list and a tuple?
  4. What is unpacking?
  5. What is a default argument?
  6. What is a keyword argument?
  7. What does len() return?
  8. What does range(5) generate?
  9. What is a list comprehension?
  10. How do you store questions in a quiz game?
  11. How do you check if an answer is correct?
  12. How do you keep score in a quiz game?
  13. How do you add difficulty levels?
  14. What is the benefit of using tuples?
  15. What is the benefit of using list comprehensions?

26. Fill-in-the-Blank

  1. _____ converts a string to uppercase. (upper())
  2. _____ splits a string into a list. (split())
  3. A _____ is an immutable list. (tuple)
  4. _____ takes values out of a tuple. (Unpacking)
  5. A _____ argument has a default value. (default)
  6. _____ returns the length of a collection. (len())
  7. _____ generates a sequence of numbers. (range())
  8. A _____ is a shorter way to create lists. (list comprehension)
  9. In a quiz game, you store questions in a _____ or list. (tuple)
  10. You use _____ to check if an answer is correct. (if/else)

27. True or False

  1. Tuples can be changed. (False)
  2. Lists can be changed. (True)
  3. upper() converts a string to lowercase. (False)
  4. split() splits a string into a list. (True)
  5. Unpacking takes values out of a tuple. (True)
  6. Default arguments cannot be used in functions. (False)
  7. len() returns the length of a string. (True)
  8. range(5) generates numbers from 1 to 5. (False โ€“ it generates 0 to 4)
  9. List comprehensions make code longer. (False)
  10. You can build games with Python. (True)

28. Multiple Choice Questions

  1. What does upper() do?
    A) Converts to uppercase B) Converts to lowercase C) Removes spaces D) Splits the string Answer: A
  2. What is a tuple?
    A) A mutable list B) An immutable list C) A dictionary D) A set Answer: B
  3. What is unpacking?
    A) Putting values into a tuple B) Taking values out of a tuple C) Creating a list D) Deleting a tuple Answer: B
  4. What is a default argument?
    A) A parameter with a default value B) A required parameter C) A keyword argument D) A return value Answer: A
  5. What does len() do?
    A) Returns the length B) Returns the sum C) Returns the average D) Returns the maximum Answer: A
  6. What does range(5) generate?
    A) 0, 1, 2, 3, 4 B) 1, 2, 3, 4, 5 C) 0, 1, 2, 3 D) 1, 2, 3, 4 Answer: A
  7. What is a list comprehension?
    A) A shorter way to create lists B) A type of loop C) A type of function D) A type of tuple Answer: A
  8. How do you check if an answer is correct?
    A) Using if/else B) Using for loop C) Using while loop D) Using try/except Answer: A
  9. What is a keyword argument?
    A) Passing arguments by name B) Passing arguments by position C) A default argument D) A return value Answer: A
  10. Which data structure is immutable?
    A) Tuple B) List C) Dictionary D) Set Answer: A
  11. Which method joins a list into a string?
    A) join() B) split() C) upper() D) strip() Answer: A
  12. Which method removes spaces from ends?
    A) strip() B) split() C) upper() D) lower() Answer: A
  13. What is a Nigerian example of a quiz game?
    A) A game about Nigerian states B) A game about US states C) A game about European countries D) A game about animals Answer: A
  14. Can you build games with Python?
    A) Yes B) No Answer: A
  15. Is Python free?
    A) Yes B) No Answer: A

29. Matching Exercises

TermDefinition
upper()A) Splits into a list
split()B) Converts to uppercase
TupleC) Immutable list
len()D) Returns length
range()E) Generates numbers

Answers: upper()-B, split()-A, Tuple-C, len()-D, range()-E


30. Short Answer Questions

  1. What is a tuple?
  2. What is the difference between split() and join()?
  3. What is unpacking?
  4. What is a default argument?
  5. What does range() do?
  6. What is a list comprehension?
  7. How do you build a quiz game?

31. Scenario-based Exercises

Scenario 1: You want to create a quiz about Nigerian states and their capitals.

Task: Write the code to store 3 questions and display them.

Answer:

  questions = [
      ("What is the capital of Lagos?", "Ikeja", "Lagos", "Abuja", "Ibadan", "A"),
      ("What is the capital of Oyo?", "Ibadan", "Oyo", "Abuja", "Lagos", "A"),
      ("What is the capital of Kano?", "Kano", "Abuja", "Ibadan", "Lagos", "A")
  ]

  for q in questions:
      print(q[0])
      print("A. " + q[1])
      print("B. " + q[2])
      print("C. " + q[3])
      print("D. " + q[4])
      answer = input("Your answer: ").upper()
      if answer == q[5]:
          print("Correct!")
      else:
          print("Wrong! Correct answer is " + q[5])

32. Group Activity

In groups of three, build an enhanced version of the Millionaire Quiz Game. Add a timer, lifelines (like 50/50), and a leaderboard. Each person takes a different part of the project.


33. Individual Activity

Write a quiz game on a topic you are passionate about โ€“ sports, music, movies, or anything else. Include at least 10 questions and a scoring system.


34. Classroom Discussion Questions

  • What was the most fun part of building the quiz game?
  • What would you add to make the game better?
  • How can you store questions in a file?
  • How can you add a timer to the game?
  • What other games can you build with Python?

35. Mini Project

Build a "Millionaire Quiz Game" with the following features:

  1. At least 10 questions.
  2. Options A, B, C, D.
  3. Score tracking.
  4. Final score display with a message.
  5. Difficulty levels (easy, medium, hard).

36. Practical Assignment

Write a complete quiz game about Nigerian culture. Include:

  1. Questions about Nigerian history, food, states, and languages.
  2. At least 15 questions.
  3. Score tracking.
  4. Feedback for correct and incorrect answers.
  5. Ability to play again.

37. Challenge Exercise

Enhance the quiz game with a timer โ€“ each question must be answered in 10 seconds. If the time runs out, the question is marked wrong. Use the time module to implement this.


38. Quiz Answers

Fill-in-the-blank: 1. upper(), 2. split(), 3. tuple, 4. Unpacking, 5. default, 6. len(), 7. range(), 8. list comprehension, 9. tuple, 10. if/else

True/False: 1F, 2T, 3F, 4T, 5T, 6F, 7T, 8F, 9F, 10T

Multiple Choice: 1A, 2B, 3B, 4A, 5A, 6A, 7A, 8A, 9A, 10A, 11A, 12A, 13A, 14A, 15A

Matching: upper()-B, split()-A, Tuple-C, len()-D, range()-E


39. Key Takeaways

  • ๐Ÿ”น String methods like upper(), lower(), split(), join() are powerful tools.
  • ๐Ÿ”น Tuples are immutable lists โ€“ they cannot be changed.
  • ๐Ÿ”น Packing and unpacking make working with multiple values easy.
  • ๐Ÿ”น Default and keyword arguments make functions flexible and clear.
  • ๐Ÿ”น len() and range() are essential for loops.
  • ๐Ÿ”น List comprehensions make code shorter and cleaner.
  • ๐Ÿ”น Building projects like a quiz game is the best way to learn.
  • ๐Ÿ”น You can build amazing things with Python!

40. Preparation for the Next Module

Congratulations! You have completed Level 1 of Python Programming. You have learned all the fundamentals โ€“ from variables to functions, from lists to dictionaries, from files to classes, and from strings to building games!

In Level 2, you will take your skills even further. You will learn:

  • How to work with external libraries.
  • How to build graphical user interfaces (GUIs).
  • How to work with APIs to get data from the internet.
  • How to build web applications with Python.
  • How to use Python for data science.
  • How to build even more advanced games.

You have built a strong foundation. The world of Python is vast and exciting. Keep coding, keep exploring, and never stop learning!


๐ŸŽ‰ Congratulations! You have completed Level 1 of Python Programming! ๐ŸŽ‰

You are now ready for Level 2 โ€“ Advanced Python!

๐Ÿ† Get Certified

๐Ÿ”’

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (โ‚ฆ2,000 or 20,000 coins), and get a verified certificate with your name on it.

๐ŸŽ“ Sign Up to Get Certified
๐Ÿ› ๏ธ Practice Tools
Hands-on simulators & labs - subscription required.
โ†’
๐ŸŽฏ Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
โ†’