Skip to content

Latest commit

 

History

History
53 lines (46 loc) · 2.34 KB

MODULE_3.md

File metadata and controls

53 lines (46 loc) · 2.34 KB

Module 3: Deeper into the functions

Module Description

This module focuses on Python namespaces and functions, including function parameters, call counting, recursion, and unpacking arguments.

Assignment 1: Homework on "Namespaces"

  • Solution
  • Description: Task "Call Counter"
    • Write 3 functions:
      1. count_calls: Tracks how many times other functions are called.
      2. string_info: Takes a string and returns a tuple containing its length, uppercase version, and lowercase version.
      3. is_contains: Takes a string and a list, returning True if the string is in the list (case-insensitive), False otherwise.
    • Track the number of times the functions are called using a counter.

Assignment 2: Homework on "Ways to Call Functions"

  • Solution
  • Description: Task "Email Sending":
    • Create a function send_email with parameters for message, recipient, and a named argument for sender with a default value.
    • Implement logic to check if emails are valid, prevent sending an email to oneself, and differentiate between default and custom senders.

Assignment 3: Homework on "Unpacking Positional Parameters"

  • Solution
  • Description: Task "Unpacking":
    • Create a function print_params with default parameters, test it with various argument combinations, and demonstrate the use of argument unpacking from lists and dictionaries.

Assignment 4: Homework on "Arbitrary Number of Parameters"

  • Solution
  • Description: Task "Single Root Words":
    • Write a function single_root_words that accepts a root word and a variable number of additional words, returning a list of words that either contain the root word or are contained by it.

Assignment 5: Independent Work on "Recursion"

  • Solution
  • Description: Task "Recursive Digit Multiplication":
    • Write a recursive function get_multiplied_digits that calculates the product of the digits of a given number.

Additional Assignment: Practical Exercise on "More About Functions"

  • Solution
  • Description: Task "One, Two, Three, Four... Is That All?":
    • Write a function that calculates the sum of all numbers and the lengths of all strings in a nested data structure, which may include lists, dictionaries, and tuples.