Day 9 - Python Homework

Advanced Practice with Functions

Now that you know the basics of functions, let’s try some challenging function problems. These tasks will test your logic, return values, and use of multiple parameters.

Hint: Break the problem into smaller steps and use return carefully!

Assignment 01: Factorial Function

Create a function that calculates factorial of a number.

Objective:

Practice loops inside a function and returning results.

Instructions:

  • Write a function factorial(n) that returns the factorial of n.
  • For example: factorial(5)120.
  • Test the function with different values of n.

Assignment 02: Palindrome Checker

Write a function to check if a word is a palindrome.

Objective:

Use string operations inside functions.

Instructions:

  • Define a function is_palindrome(word).
  • The function should return True if the word is a palindrome, else False.
  • Example: is_palindrome("madam")True.

Assignment 03: Calculator Function

Create a function that works like a simple calculator.

Objective:

Understand how to handle multiple parameters and conditions inside a function.

Instructions:

  • Write a function calculator(a, b, operator).
  • The operator can be +, -, *, /.
  • Return the result based on the operator.
  • Example: calculator(10, 5, "*")50.

If you need help

Ask for help if you are stuck on:

Good luck! These are tricky but fun 🚀