Skip to content

Latest commit

 

History

History
47 lines (37 loc) · 2.48 KB

File metadata and controls

47 lines (37 loc) · 2.48 KB

Module 4: Functions

Activity 1: Introduction to functions

  • Understanding the concept of functions and their importance in programming.
  • Exploring the syntax of function declaration and function definitions.
  • Learning about function names and best practices for naming functions.
  • Understanding the purpose of function documentation and comments.

Activity 2: Declaring and calling functions

  • Declaring functions with parameters and return statements.
  • Calling functions and passing arguments.
  • Understanding function scope and variable visibility.
  • Exploring function hoisting and function expressions.

Activity 3: Parameters and return values

  • Working with function parameters and understanding their role in passing data to functions.
  • Exploring different types of function parameters: required parameters, default parameters, and variable-length parameters.
  • Using return statements to return values from functions.
  • Understanding the concept of function purity and side effects.

Practice Exercises:

  1. Calculate the area of a circle:

    • Write a function called calculate_area that takes the radius of a circle as a parameter.
    • Inside the function, calculate the area of the circle using the formula: area = 3.14159 * radius * radius.
    • Return the calculated area from the function.
    • Call the function with different radius values and print the result.
  2. Reverse a string:

    • Write a function called reverse_string that takes a string as a parameter.
    • Inside the function, reverse the order of characters in the string.
    • Return the reversed string from the function.
    • Call the function with different strings and print the result.
  3. Check if a number is prime:

    • Write a function called is_prime that takes a number as a parameter.
    • Inside the function, check if the number is prime (i.e., divisible only by 1 and itself).
    • Return True if the number is prime, and False otherwise.
    • Call the function with different numbers and print the result.

Estimated time to complete this module is approximately 4-6 hours.

To further enhance your learning, here are some additional resources: