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

Practice Lab

๐Ÿ“– 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.
5
Practice Lab ยท Python Level 1

๐Ÿ Practice Lab: Python Programming Level 1

1. Lab Title

Practice Lab: Python Programming Level 1 โ€“ Hands-On Exercises


2. Lab Introduction

Welcome, young coder! You have completed all the lessons in Level 1 of Python Programming. Now it's time to practice what you have learned. This lab is full of hands-on exercises that will help you become a better programmer. Each exercise is designed to test a specific skill you learned in the course.

Don't worry if you make mistakes โ€“ that's how we learn! Try each exercise on your own first. If you get stuck, look back at your notes or ask for help. The goal is to practice, not to be perfect. Let's get coding!


3. Learning Objectives

After completing this lab, you will be able to:

  • Write Python programs from scratch using all the concepts you learned.
  • Use variables, data types, and input/output correctly.
  • Write conditional statements (if/elif/else) to make decisions.
  • Use loops (while and for) to repeat tasks.
  • Work with lists, tuples, dictionaries, and sets.
  • Write functions with parameters and return values.
  • Read from and write to files.
  • Handle errors using try/except.
  • Build small projects using all these skills.

4. Warm-up Story

Chidi's Coding Practice

Chidi had learned so much about Python. He could write variables, loops, functions, and even build a quiz game. But his teacher said, "Chidi, the best way to get better at coding is to practice every day. Just like playing football or learning an instrument โ€“ practice makes perfect!"

Chidi decided to practice coding every day. He started with simple exercises โ€“ printing messages, calculating numbers, and asking for user input. Then he moved to harder exercises โ€“ writing functions, working with lists, and building small programs. Each day, he got a little better. Soon, he could solve problems that were difficult before.

Now, it's your turn to practice! This lab has many exercises to help you become a confident Python programmer.


5. Lab Exercises

Exercise 1: Hello, World! (Print Statements)

Task: Write a Python program that prints the following messages:

  1. "Hello, World!"
  2. "Welcome to Python Programming!"
  3. "I am learning to code!"

Expected Output:

Hello, World!
Welcome to Python Programming!
I am learning to code!

Hint: Use the print() function.


Exercise 2: Variables and Data Types

Task: Create a program that does the following:

  1. Create a variable called name and store your name.
  2. Create a variable called age and store your age.
  3. Create a variable called height and store your height in meters (e.g., 1.55).
  4. Create a variable called is_student and store True.
  5. Print all the variables.

Example Output:

Name: Ada
Age: 10
Height: 1.55
Is student: True

Hint: Use print("Name:", name) or f-strings.


Exercise 3: User Input

Task: Write a program that does the following:

  1. Ask the user for their name.
  2. Ask the user for their favourite food.
  3. Print a message like "Hello [name]! [food] sounds delicious!"

Example Interaction:

What is your name? Ada
What is your favourite food? Jollof Rice
Hello Ada! Jollof Rice sounds delicious!

Hint: Use input() to get user input and print() to display the result.


Exercise 4: Conditional Statements (if/else)

Task: Write a program that asks the user for their age. If the age is 18 or above, print "You are an adult." Otherwise, print "You are a child."

Example Interaction 1:

How old are you? 20
You are an adult.

Example Interaction 2:

How old are you? 10
You are a child.

Hint: Use int() to convert user input to an integer.


Exercise 5: More Conditional Statements (elif)

Task: Write a program that asks the user for a number and does the following:

  1. If the number is positive, print "Positive".
  2. If the number is negative, print "Negative".
  3. If the number is zero, print "Zero".

Example Interactions:

Enter a number: 5
Positive

Enter a number: -3
Negative

Enter a number: 0
Zero

Hint: Use if, elif, and else.


Exercise 6: While Loop

Task: Write a program that uses a while loop to print numbers from 1 to 10.

Expected Output:

1
2
3
4
5
6
7
8
9
10

Hint: Start a counter at 1 and increment it until it reaches 10.


Exercise 7: For Loop

Task: Write a program that uses a for loop to print the numbers 1 to 10.

Expected Output:

1
2
3
4
5
6
7
8
9
10

Hint: Use range(1, 11).


Exercise 8: Lists

Task: Write a program that does the following:

  1. Create a list of 5 favourite fruits.
  2. Print the first fruit.
  3. Print the last fruit.
  4. Add a new fruit to the list.
  5. Remove the second fruit.
  6. Print the final list.

Example Output:

First fruit: Mango
Last fruit: Orange
Final list: ['Mango', 'Banana', 'Orange', 'Pineapple']

Hint: Use list methods like append(), remove(), and indexing.


Exercise 9: Looping Through a List

Task: Write a program that loops through a list of numbers and prints each number multiplied by 2.

Example Input:

numbers = [1, 2, 3, 4, 5]

Expected Output:

2
4
6
8
10

Hint: Use a for loop to go through the list.


Exercise 10: Dictionaries

Task: Write a program that does the following:

  1. Create a dictionary that stores the names and ages of 3 people.
  2. Print the age of one person.
  3. Add a new person.
  4. Change the age of an existing person.
  5. Print the final dictionary.

Example Output:

Ada's age: 10
Final dictionary: {'Ada': 10, 'Chidi': 12, 'Bola': 11, 'Tunde': 9}

Hint: Use curly braces {} to create a dictionary.


Exercise 11: Functions

Task: Write a function called greet that takes a name as a parameter and prints "Hello, [name]!". Then call the function with three different names.

Expected Output:

Hello, Ada!
Hello, Chidi!
Hello, Bola!

Hint: Use def greet(name):.


Exercise 12: Functions with Return Values

Task: Write a function called add that takes two numbers as parameters and returns their sum. Then call the function with different numbers and print the results.

Example Output:

5 + 3 = 8
10 + 20 = 30
7 + 2 = 9

Hint: Use return to send the value back.


Exercise 13: File Writing

Task: Write a program that does the following:

  1. Ask the user for their name.
  2. Ask the user for their age.
  3. Write this information to a file called "user_info.txt".

Hint: Use open("user_info.txt", "w") and write().


Exercise 14: File Reading

Task: Write a program that reads and prints the contents of a file called "user_info.txt". If the file doesn't exist, handle the error with try/except.

Hint: Use open("user_info.txt", "r") and read(). Use try/except to handle the error.


Exercise 15: Error Handling

Task: Write a program that asks the user for a number. If the user enters something that is not a number, print "That is not a valid number!" and ask again.

Hint: Use a while loop and try/except.


Exercise 16: Tuples

Task: Create a tuple with 5 of your favourite things (movies, foods, games, etc.). Print the tuple. Then, try to change an item (it should cause an error).

Hint: Use parentheses () for tuples.


Exercise 17: Packing and Unpacking

Task: Create a tuple with three values (name, age, city). Unpack the tuple into three variables and print them.

Example Output:

Name: Ada
Age: 10
City: Lagos

Hint: Use name, age, city = my_tuple.


Exercise 18: Sets

Task: Create a set of 5 favourite colours. Add a new colour. Try to add a duplicate โ€“ notice it doesn't change. Print the set.

Hint: Use curly braces {} for sets.


Exercise 19: List Comprehensions

Task: Use a list comprehension to create a list of squares of numbers from 1 to 10.

Expected Output:

[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

Hint: Use [i * i for i in range(1, 11)].


Exercise 20: Mini Project โ€“ Simple Calculator

Task: Build a simple calculator program that:

  1. Asks the user for two numbers.
  2. Asks the user for an operation (+, -, *, /).
  3. Performs the calculation and prints the result.
  4. Handles errors if the user enters invalid input.

Example Interaction:

Enter first number: 10
Enter second number: 5
Enter operation (+, -, *, /): +
10 + 5 = 15

Hint: Use functions, if/elif/else, and try/except.


6. Key Vocabulary

  • Variable: A container for storing data.
  • Data Type: The kind of data (integer, string, float, boolean).
  • Input: Data given to a program by the user.
  • Output: Data displayed by a program.
  • Conditional: A statement that makes a decision (if/else).
  • Loop: Code that repeats (while, for).
  • List: A collection of items (mutable).
  • Tuple: A collection of items (immutable).
  • Dictionary: Key-value pairs.
  • Set: A collection of unique items.
  • Function: A reusable block of code.
  • File: A place to store data permanently.
  • Error Handling: Catching and managing errors.

7. Important Concepts

  • Practice makes perfect: The more you code, the better you become.
  • Read the error messages: They tell you what is wrong.
  • Break problems into small steps: Don't try to solve everything at once.
  • Use comments: They help you understand your code.
  • Test your code often: Run it after each change.

8. Step-by-step Explanations

How to complete a lab exercise:

  1. Read the exercise carefully.
  2. Understand what the program should do.
  3. Write the code step by step.
  4. Run the program and test it.
  5. If there is an error, read the error message and fix it.
  6. When it works, move to the next exercise.

9. Real-life Examples

  • A calculator app on a phone.
  • A contact list in a phone book.
  • A shopping list for groceries.
  • A grade calculator for school.
  • A game on a computer.

10. Nigerian Examples

  • A program that converts Naira to Dollars.
  • A program that lists Nigerian states.
  • A program that calculates market prices.
  • A program that helps with school grades.
  • A program that stores contact information.

11. Fun Examples Children Can Relate To

  • A program that tells a joke.
  • A program that counts down to a birthday.
  • A program that stores favourite games.
  • A program that asks for a favourite cartoon.
  • A program that makes a simple game.

12. Everyday Examples

  • ๐Ÿ“ฑ A calculator.
  • ๐Ÿ“ A to-do list.
  • ๐Ÿ“… A birthday reminder.
  • ๐Ÿ›’ A shopping list.
  • ๐Ÿ“Š A grade calculator.

13. Teacher Notes

This lab is designed to be self-paced. Students can work at their own speed. Encourage them to help each other. Circulate and provide guidance. Celebrate their achievements, no matter how small. Remind them that making mistakes is part of learning.


14. Parent Tips

Help your child set up their coding environment. Sit with them as they work on the exercises. Ask questions like "What do you think this code does?" and "What happens if you change this value?" Celebrate their progress and encourage them to keep going.


15. Interesting Facts

  • ๐Ÿ’ป The first computer programmer was a woman named Ada Lovelace.
  • ๐Ÿ Python was named after Monty Python, not the snake.
  • ๐Ÿ“Š Python is used by Google, NASA, and Instagram.
  • ๐ŸŒ Python is one of the most popular programming languages in the world.
  • ๐ŸŽฎ You can build games with Python!

16. Did You Know?

  • Python is used in artificial intelligence and machine learning.
  • Many Nigerian developers use Python to build apps.
  • Python is free and open source.
  • You can use Python to build websites.
  • Python is a great first language to learn.

17. Remember This

  • โœ… Practice every day.
  • โœ… Read error messages โ€“ they help you.
  • โœ… Break problems into small steps.
  • โœ… Test your code often.
  • โœ… Help others โ€“ it helps you too!

18. Common Mistakes

  • โŒ Forgetting colons : after if, else, while, for, def.
  • โŒ Forgetting to indent code.
  • โŒ Using = instead of == for comparison.
  • โŒ Not converting input to the right data type.
  • โŒ Forgetting to close parentheses or quotes.

19. Best Practices

  • โœ… Use meaningful variable names.
  • โœ… Add comments to explain your code.
  • โœ… Use consistent indentation.
  • โœ… Test your code frequently.
  • โœ… Start small and add features gradually.

20. Illustrations

Lab Exercise Flowchart

  +-------------+     +-------------+     +-------------+     +-------------+
  |  READ       | --> |  UNDERSTAND | --> |  WRITE      | --> |  TEST       |
  |  EXERCISE   |     |  THE TASK   |     |  THE CODE   |     |  THE CODE   |
  +-------------+     +-------------+     +-------------+     +-------------+
       |                                                           |
       |                                                           V
       |                                                  +-------------+
       +--------------------------------------------------|  DEBUG      |
                                                          |  IF NEEDED  |
                                                          +-------------+
                                                               |
                                                               V
                                                          +-------------+
                                                          |  MOVE TO    |
                                                          |  NEXT       |
                                                          |  EXERCISE   |
                                                          +-------------+

Comparison Table โ€“ Data Structures

Data StructureMutableOrderedDuplicatesExample
ListYesYesYes[1, 2, 3]
TupleNoYesYes(1, 2, 3)
DictionaryYesYes (3.7+)Keys: No, Values: Yes{"a": 1, "b": 2}
SetYesNoNo{1, 2, 3}

23. End-of-Lab Summary

Great job completing this practice lab! You have written many programs using all the skills you learned in Level 1. You used variables, data types, input/output, conditional statements, loops, lists, dictionaries, functions, files, error handling, tuples, sets, and list comprehensions.

Remember, becoming a great programmer takes time and practice. Keep coding every day, even if it's just for 15 minutes. Try building your own projects โ€“ a game, a calculator, or a personal diary. The more you code, the better you will become. You are on the right path!


24. Frequently Asked Questions

  1. What should I do if I get stuck? Read the error message, look at your code, and try to find the mistake. You can also ask a teacher or friend for help.
  2. How many exercises should I do in one day? As many as you can. Quality is more important than quantity. Take your time to understand each exercise.
  3. Can I use the internet to help? Yes! Looking up solutions and examples is a great way to learn. Just make sure you understand the code you use.
  4. What if my code doesn't work? That's normal! Debugging is part of programming. Try to find the error, fix it, and try again.
  5. What is the most important thing to remember? Practice, practice, practice! The more you code, the better you become.
  6. Can I share my code with others? Yes! Sharing code and helping others is a great way to learn.
  7. What if I can't finish all exercises? That's okay. Do what you can and come back to the rest later.
  8. Can I use these exercises for my portfolio? Yes! These exercises show your skills and progress.
  9. What should I learn next? After Level 1, you can move to Level 2 or start building your own projects.
  10. Is Python a good language to learn? Yes! Python is one of the most popular and beginner-friendly programming languages.

25. Review Questions

  1. How do you print a message in Python?
  2. How do you get user input?
  3. What is the difference between = and ==?
  4. What does if/else do?
  5. How do you write a while loop?
  6. How do you write a for loop?
  7. What is a list?
  8. How do you add an item to a list?
  9. What is a dictionary?
  10. How do you define a function?
  11. What does return do?
  12. How do you read from a file?
  13. How do you write to a file?
  14. What is a tuple?
  15. What is a set?

26. Fill-in-the-Blank

  1. _____ prints a message to the screen. (print)
  2. _____ gets user input. (input)
  3. _____ makes decisions in a program. (if)
  4. A _____ loop repeats code as long as a condition is true. (while)
  5. A _____ loop repeats code a set number of times. (for)
  6. A _____ is a collection of items (mutable). (list)
  7. A _____ is a collection of key-value pairs. (dictionary)
  8. A _____ is a reusable block of code. (function)
  9. _____ returns a value from a function. (return)
  10. A _____ is a collection of unique items. (set)

27. True or False

  1. print("Hello") prints Hello. (True)
  2. input() gets user input. (True)
  3. = is used for comparison. (False โ€“ it's used for assignment)
  4. == is used for comparison. (True)
  5. A while loop runs a set number of times. (False โ€“ it runs while a condition is true)
  6. A for loop runs a set number of times. (True)
  7. Lists are immutable. (False โ€“ they are mutable)
  8. Tuples are immutable. (True)
  9. Dictionaries store key-value pairs. (True)
  10. Sets allow duplicate items. (False โ€“ they only store unique items)

28. Multiple Choice Questions

  1. How do you print "Hello" in Python?
    A) echo("Hello") B) print("Hello") C) printf("Hello") D) output("Hello") Answer: B
  2. How do you get user input?
    A) input() B) get() C) read() D) scan() Answer: A
  3. What does if do?
    A) Makes a decision B) Repeats code C) Stores data D) Prints data Answer: A
  4. What is a variable?
    A) A container for data B) A loop C) A function D) A file Answer: A
  5. What is a list?
    A) A collection of items B) A key-value pair C) A loop D) A function Answer: A
  6. What is a dictionary?
    A) Key-value pairs B) A collection of items C) A loop D) A function Answer: A
  7. How do you define a function?
    A) def function_name(): B) function function_name(): C) fun function_name(): D) define function_name(): Answer: A
  8. What does return do?
    A) Sends a value back B) Prints a value C) Loops code D) Creates a variable Answer: A
  9. What is a tuple?
    A) An immutable list B) A mutable list C) A dictionary D) A set Answer: A
  10. What is a set?
    A) A collection of unique items B) A collection of duplicates C) A key-value pair D) A loop Answer: A
  11. Which data structure is immutable?
    A) Tuple B) List C) Dictionary D) Set Answer: A
  12. Which data structure stores unique items?
    A) Set B) List C) Tuple D) Dictionary Answer: A
  13. Which data structure stores key-value pairs?
    A) Dictionary B) List C) Tuple D) Set Answer: A
  14. Can Python be used to build games?
    A) Yes B) No Answer: A
  15. Is Python free?
    A) Yes B) No Answer: A

29. Matching Exercises

TermDefinition
print()A) Gets user input
input()B) Displays output
ifC) Repeats code
whileD) Makes a decision
forE) Repeats a set number of times

Answers: print()-B, input()-A, if-D, while-C, for-E


30. Short Answer Questions

  1. How do you print a message in Python?
  2. How do you get user input?
  3. What is the difference between a list and a tuple?
  4. What is a dictionary?
  5. What is a set?
  6. How do you define a function?
  7. What does return do?

31. Scenario-based Exercises

Scenario 1: You want to store the names of 5 of your friends in a list. Then, you want to print each name one by one.

Task: Write the code to do this.

Answer:

  friends = ["Ada", "Chidi", "Bola", "Tunde", "Kemi"]
  for friend in friends:
      print(friend)

Scenario 2: You want to create a program that asks the user for their age and tells them if they are a child (under 18) or an adult (18 and above).

Task: Write the code to do this.

Answer:

  age = int(input("How old are you? "))
  if age >= 18:
      print("You are an adult.")
  else:
      print("You are a child.")

32. Group Activity

In groups of three, work together to complete all the lab exercises. Each person can take turns being the "driver" (writing code) and the "navigator" (reading and suggesting ideas). Help each other debug and learn.


33. Individual Activity

Choose 3 exercises from this lab that you found most challenging. Redo them from scratch without looking at your previous answers. This will help you understand the concepts better.


34. Classroom Discussion Questions

  • Which exercise was the most challenging? Why?
  • What is one new thing you learned while doing this lab?
  • Which concept do you still find confusing?
  • How can you use Python in your daily life?
  • What project would you like to build next?

35. Mini Project

Build a program that acts as a Personal Diary. The program should:

  1. Ask the user for today's date.
  2. Ask the user to write a diary entry.
  3. Save the entry to a file.
  4. Give the user the option to view all past entries.
  5. Handle errors (e.g., missing file, invalid input).

36. Practical Assignment

Complete all 20 exercises in this lab. For each exercise, write the code, test it, and save it in a file named lab_exercise_X.py (where X is the exercise number). Submit all files to your teacher.


37. Challenge Exercise

Build a program that allows the user to create a To-Do List. The program should:

  1. Allow the user to add tasks.
  2. Allow the user to view all tasks.
  3. Allow the user to mark a task as complete.
  4. Allow the user to delete a task.
  5. Save the tasks to a file.
  6. Load tasks from the file when the program starts.

38. Quiz Answers

Fill-in-the-blank: 1. print, 2. input, 3. if, 4. while, 5. for, 6. list, 7. dictionary, 8. function, 9. return, 10. set

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

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

Matching: print()-B, input()-A, if-D, while-C, for-E


39. Key Takeaways

  • ๐Ÿ”น Practice is the key to becoming a great programmer.
  • ๐Ÿ”น Read error messages โ€“ they tell you what is wrong.
  • ๐Ÿ”น Break problems into small, manageable steps.
  • ๐Ÿ”น Test your code often to catch errors early.
  • ๐Ÿ”น Help others โ€“ it helps you learn too!
  • ๐Ÿ”น Have fun and enjoy the process of learning.

40. Preparation for the Next Module

Congratulations on completing the practice lab! You have now practiced all the skills from Level 1. You are ready to move on to Level 2 โ€“ Advanced Python Concepts.

In Level 2, you will learn:

  • More advanced functions (lambda, higher-order).
  • Working with modules and libraries.
  • Building graphical user interfaces (GUIs).
  • Web development with Python.
  • Working with data (CSV, JSON).
  • Building larger, more complex projects.

Keep coding, keep exploring, and never stop learning. You have built a strong foundation โ€“ now go and build amazing things!


๐ŸŽ‰ Congratulations! You have completed the Python Programming Level 1 Practice Lab! ๐ŸŽ‰

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

๐Ÿ† 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.
โ†’