Professional Documents
Culture Documents
Seminar 7
Seminar 7
WEEK 7 – SEMINAR
tanser.karakash@navitas.com
Lecture recap
Practice exercises
Sample exam exercises
Write a function to accept 3 numbers from the user, calculate their sum and print it.
Write a program to accept three numbers from the user. Pass these variables into a function to calculate their sum and
print it.
Write a program to accept three numbers from the user. Pass these variables into a function to calculate their sum and
print it. If only two inputs are passed into the function, then use 3.14 as the third number.
Write a program to accept three numbers from the user. Pass these variables into a function to calculate their sum and
return it. Write another function to calculate and print the square of any number. Calculate the square of the return
value from the first function.
Write a function that takes a list of user defined numbers as an input. The function should sort the numbers into even
and odd and return two lists: one containing even numbers and one containing odd numbers.
In a new file, import and call the method written in an earlier exercise to sort values into even and odd lists.
Write a program to import the variable pi from the module called math. Use this to calculate the area of a circle of
radius 10 units.
Write a program to import the module called math with the alias ‘m’. Use the methods and values from the
math module to calculate the sin of pi/2
10
In a file called max_height_calc.py write a function that calculates the maximum height of a projectile by taking
the launch velocity, launch angle, initial height and acceleration due to gravity.
In another file called user_input.py ask the user to enter the parameters and store them in a list. Import the
function from max_height_calc.py and print the maximum height of a projectile.
11
Write a Python module called ‘temperature_converter’ that contains a function named ‘convert_temp’. The
function should take a temperature value in Fahrenheit as input and return the equivalent temperature in Celsius or the
vice versa , depending on the wishes of the user. Then, in your main file, write a code which imports the
‘temperature_converter’ module and allows the user to convert temperatures. After displaying the converted
temperature, ask the user if they want to continue converting or exit. Make sure to handle error cases.
12
Implement a function called ‘binary_search’ that takes a sorted list and a target value as input. The function should
perform a binary search algorithm to find the index of the target value in the list. If the value is found, return its
index; else, return -1.
13
The Dutch BSN (Burgerservicenummer) is a unique personal identification number used in the Netherlands. It
consists of 9 digits and follows a specific algorithm for validation. Write a Python program that implements a
function called ‘validate_bsn’ which takes a BSN as input and returns True if the BSN is valid, and False otherwise.
How to validate a Dutch BSN:
1. Check if the BSN is exactly 9 digits long.
2. Multiply each digit by its corresponding weight factor (9, 8, 7, 6, 5, 4, 3, 2, 1).
3. Sum up the products.
4. If the sum is divisible by 11, the BSN is valid.
Make sure you return a boolean value indicating whether the BSN is valid or nor and a message describing the reason
if the BSN is valid. Provide more context about why the validation failed.
14
15
Information Classification: Confidential