This section contains the exercises for Module 2 of the course materials. Feel free to practice and enhance your skills with the following exercises.
Exercise 1: Introduction to Variables
In this exercise, you will learn how to declare and use variables in your code.
Task:
Write a program that declares three variables: name
, age
, and country
. Assign appropriate values to each variable and print them out.
# Your code here
Exercise 2: Control Structures
This exercise focuses on using control structures like if
, elif
, and else
to make decisions in your code.
Task: Write a program that asks the user for their age and prints out a message based on the age range:
- Under 18: "You are a minor."
- 18-65: "You are an adult."
- Over 65: "You are a senior."
# Your code here
Exercise 3: Functions
Functions allow you to encapsulate a block of code for reuse. In this exercise, you will create a function that calculates the sum of two numbers.
Task:
Write a function named add
that takes two parameters, a
and b
, and returns their sum. Then, call the function with two example numbers and print the result.
# Your code here
For more information on functions, you can read about function definitions.