Lab Problems-Python Functions
Recursive Functions
Concept Overview Video: https://youtu.be/ZdD3HGEejLU?si=dsaArfnpFbIyQaYt
Recursive Factorial Calculation
Write a recursive function to calculate the factorial of a given positive integer. Use it to find
the factorial of a user-provided number.
Example:
Input: `5`
Output: `120`
Fibonacci Sequence Generator
Create a recursive function that generates the nth Fibonacci number. The function should
also print all Fibonacci numbers up to that point.
Example:
Input: `5`
Output: `0, 1, 1, 2, 3, 5`
Recursive Sum of Digits
Write a recursive function that computes the sum of the digits of a positive integer.
Example:
Input: `4321`
Output: `4 + 3 + 2 + 1 = 10`
Built-in Functions
Concept Overview Video: https://youtu.be/SRc2a4XKcQ4?si=suE13-uupH-Tg4e8
Sum of Absolute Differences
Write a Python program that takes a list of integers as input and uses the `abs()` and `sum()`
built-in functions to compute the sum of the absolute differences between consecutive
elements in the list.
Example:
Input: [3, -5, 8, 2]
Output: `|3 - (-5)| + |-5 - 8| + |8 - 2| = 8 + 13 + 6 = 27`
User-Defined Functions
Concept Overview Videos: https://youtu.be/YrRW22tqX4E?si=hYFvg7KDB-iccW7q and
https://youtu.be/nFCfnG2QX9E?si=0D5cf8BlbYwsLJ1R
Simple Calculator
Implement a simple calculator using functions for addition, subtraction, multiplication, and
division. Allow the user to input the operation they want to perform, followed by two
numbers. Utilize default parameter values in one of the functions.
Example:
Input: 'Multiply 5 3'
Output: `15`
Additional Problems:
Character Frequency Counter
Create a function that takes a string as input and returns a dictionary where the keys are
characters, and the values are the frequency of their appearance. Use the `len()` and `ord()`
functions as part of the solution.
Example:
Input: 'hello'
Output: `{'h': 1, 'e': 1, 'l': 2, 'o': 1}`
Prime Checker with Arbitrary Arguments
Define a function that accepts an arbitrary number of integer arguments (`*args`) and
returns a list of those that are prime numbers.
Example:
Input: `prime_checker(2, 4, 5, 6, 7)`
Output: `[2, 5, 7]`