Functions Challenges and Projects
Functions Challenges and Projects
Great job finishing this module.
You have learned how to use:
- functions
- parameters
- arguments
- return values
- scope
- keyword arguments
- lambda functions
- recursion
- docstrings
Now it is time to practice everything together.
Quick Challenges
Try to solve these on your own.
Challenge 1: Greeting Function
Build a greeting function.
Steps:
- Create a function called
greet - Give it one parameter called
name - Print:
Helloand the name - Call the function with your name
Expected output:
Hello Sara
Challenge 2: Square Function
Build a square function.
Steps:
- Create a function called
square - Give it one parameter called
number - Return the square of the number
- Print the result of
4
Expected output:
16
Challenge 3: Keyword Profile
Build a profile function.
Steps:
- Create a function with parameters:
name,age - Print both values
- Call the function using keyword arguments
Expected output:
Maya 25
Challenge 4: Countdown Recursion
Build a recursive countdown.
Steps:
- Create a function called
countdown - If number is
0, print:
Go! - Otherwise:
- Print the number
- Call the function again with
number - 1
Expected output for countdown(3):
3
2
1
Go!
Mini Projects
These projects combine many skills.
Project 1: Reusable Calculator
Build a calculator using functions.
Steps:
- Create these functions:
add(a, b)subtract(a, b)multiply(a, b)divide(a, b)
- Each function should return the answer
- Print results using
10and2
Expected output:
12
8
20
5.0
Project 2: Student Result Checker
Build a student result app.
Steps:
- Create a function called
result - Give it parameters:
name,score
Rules:
- If score is 80 or more, return
Excellent - If score is 50 or more, return
Pass - Otherwise, return
Fail
Then print:
Name: Result
Expected output:
Sara: Pass
Project 3: Text Formatter
Build a text tool.
Steps:
- Create a function called
format_text - Give it one parameter called
text - Return:
- uppercase text
- lowercase text
- title case text
Print all results.
Expected output for python course:
PYTHON COURSE
python course
Python Course
Project 4: Login Function
Build a login checker.
Steps:
- Store correct username as
admin - Store correct password as
python123 - Create a function called
login - Give it parameters:
username,password
Rules:
- If both values are correct, return:
Login successful - Otherwise, return:
Invalid login
Print the result.
Expected output:
Login successful
Final Challenge
Build a mini banking app.
Steps:
- Create a function called
deposit(balance, amount) - Return new balance after adding amount
- Create a function called
withdraw(balance, amount)
Rules:
- If amount is greater than balance, return:
Not enough money - Otherwise, return new balance
- Add docstrings to both functions
- Test your functions with example values
Expected output:
150
120
Not enough money
Real World Use Case
Real programs are built with functions. Websites, games, apps, and automation tools all use reusable functions to stay organized.
Quiz
- What does
returndo? - What is a parameter?
- Why are functions useful?
- What is recursion?
Assignment
Choose one mini project and improve it by adding more features or cleaner output.
Summary
You completed the Functions module and practiced building reusable Python programs with real function skills.