You are on page 1of 1

Lab 9 Exercises – Functions

Date: 27.03.2024
1. Write a function that takes a list of strings as input and returns a new list containing
the lengths of those strings. Test it with various input lists.
2. Write a function that takes a list of numbers as input and returns the maximum and
minimum values. Test it with different lists.
3. Create a function that takes a string and a number as input and prints the string that
many times. Test it with different inputs.
4. Define and test a function myRange. This function should behave like Python’s
standard range function, with the required and optional arguments, but should return a
list. Do not use the range function in your implementation! (Hints: Study Python’s
help on range to determine the names, positions, and what to do with your function’s
parameters.
Use a default value of None for the two optional parameters. If these parameters both
equal None, then the function has been called with just the stop value. If just the third
parameter equals None, then the function has been called with a start value as well.
Thus, the first part of the function’s code establishes what the values of the
parameters are or should be. The rest of the code uses those values to build a list by
counting up or down.)
5. The factorial of a positive integer n, fact(n), is defined recursively as follows:
fact(n)=1, when n=1
fact(n)=n*fact(n–1), otherwise
Define a recursive function fact that returns the factorial of a given positive integer.
6. Create a function that takes a variable number of arguments and returns their sum.
Test this function with different numbers of arguments passed and verify the results.
7. Create a function that takes a string as input and prints it in uppercase.
Modify the function to have a default argument such that if no argument is passed, it
prints "Hello, World!" in uppercase.
Test both scenarios - with and without providing input to the function.

You might also like