In this assignment, you will implement several basic Python functions to practice working with:
- Arithmetic operations
- Control flow and conditionals
- Loops and recursion
- Error handling
- String and list manipulation
All your functions will be tested automatically using the unittest framework.
Your goal is to write the code so that all tests pass successfully.
All functions must be written in basic_functions.py.
Do not rename any of the functions or change their parameters.
- Do not modify the test file.
- Do not hardcode answers.
- Ensure your code runs without errors.
- Keep your code clean and readable.
Description:
Return the sum of two numbers.
Examples:
add(1, 1) ➜ 2Description:
Return the result of subtracting b from a.
Examples:
subtract(2, 1) ➜ 1Description:
Return the product of two numbers.
Examples:
multiply(3, 3) ➜ 9Description:
Return the result of dividing a by b.
If b is 0, raise a ValueError.
Examples:
divide(10, 2) ➜ 5
divide(5, 0) ➜ ❌ raises ValueErrorDescription:
Return:
"Fizz"if the number is divisible by 3"Buzz"if the number is divisible by 5"FizzBuzz"if divisible by both 3 and 5- Otherwise, return the number itself.
Examples:
fizz_buzz(3) ➜ "Fizz"
fizz_buzz(5) ➜ "Buzz"
fizz_buzz(15) ➜ "FizzBuzz"
fizz_buzz(7) ➜ 7Description:
Return the n-th Fibonacci number.
The Fibonacci sequence starts as:
0, 1, 1, 2, 3, 5, ...
Each number is the sum of the two before it:
F(0) = 0
F(1) = 1
F(n) = F(n-1) + F(n-2)
Examples:
fibonacci(0) ➜ 0
fibonacci(1) ➜ 1
fibonacci(10) ➜ 55Description:
Return a list of strings representing a triangle made of asterisks (*).
Each level of the triangle increases by two * characters.
Examples:
triangle(0) ➜ []
triangle(1) ➜ ["*"]
triangle(2) ➜ ["*", "***"]
triangle(3) ➜ ["*", "***", "*****"]
triangle(4) ➜ ["*", "***", "*****", "*******"]