Home Schedule

Lab 4: Functions (10 pts)

Part I: Setup

  1. Locate your "CS102" folder
  2. Create a folder inside "CS102" called "lab04"
  3. Download lab04.py
  4. Move the "lab04.py" file into your lab04 folder
  5. Open "lab04.py" with Thonny
  6. Submit lab04.py to Moodle when you are finished

Part II: Writing Functions

Now that we are writing functions, make sure your work today (and all future assignments) follows our class Python style guidelines and you include function comments. Be careful of your indentation!

NOTE: For each function your write, make sure you have at least one call to the functions you've created in the main function.

  1. Read over the comments
  2. Write a function that has no input parameters that always returns 7.
  3. Write a function that takes three numbers as input parameters and returns their sum.
  4. Write a function that takes two numbers as input paramaters and returns their product.
  5. Write a function that takes four numbers as input parameters and returns the sum of the first two multiplied by the sum of the last two.
  6. Write a function that takes an two input parameters. The first is an integer and the second is a string that represents a number. The function returns is the remainder of the first integer divided by the integer value of the string.
    • For example, if you input 17 and "7" to your function, the returned value should be 3, since the remainder is 3 when 17 is divided by 7.
  7. Write a function that takes two strings and an integer as input parameters and returns a new string which combines the first two strings and repeats them the same number of times as the integer parameter.
    • For example, if the inputs are "Multimedia", "Computing", and 3, the returned string would be: "MultimediaComputingMultimediaComputingMultimediaComputing"

Part III: Composition of Functions

  1. Write a function that takes six numbers as input parameters and returns the sum of the first three multiplied by the sum of the last three. You may not use + or * in the body of this function, but you may call other functions you’ve written.