Python Basics Review#
Let’s refresh some Python basics. In this notebook, you will find exercises covering the following concepts:
Data structures
Conditions and loops
Basic operations on data
Using packages
User-defined functions
Try to solve the following exercises. If you need help, You may use our AI assistant bia-bob, as introduced in the previous notebooks.
# Import bia-bob
# Initialize bia-bob with model, and custom system prompt if preferred
Exercise 1#
Concepts: variables, data types, indexing, basic math operations
Scenario#
You are provided with basic information about a patient’s vital signs during a check-up:
name: Lisa
age (years): 42
weight (kg): 72.0
height (cm): 178
heart rate measurements (bpm): 72,75,70,78,74,68,91,76,105
Tasks#
Store the data in variables with suitable data types, print the data types
Compute:
BMI = weight / height²
heart beats per hour
Extract the values for:
minimum heart rate
maximum heart rate
average heart rate
# Your turn...
Exercise 2#
Concepts: file I/O, dictionaries, loops, conditions
Scenario#
You receive basic measurements for several patients in a CSV file: patient_measurements.csv
Tasks#
Read the data from the file and store it in a dictionary
Loop over all patients, and for each patient:
Print the patient ID and systolic blood pressure
Classify blood pressure as “normal” (< 130), or “high” (≥ 130)
Count how many patients fall into each category
# Your turn...
Exercise 3#
Concepts: selecting / filtering data, creating new data structures
Scenario#
From the patient measurements dataset dictionary from excercise 2, you want to identify patients with specific symptoms.
Tasks#
Create a list of patient IDs with temperature ≥ 38.0 °C
Create a new dictionary containing only patients with high blood pressure (SBP ≥ 130)
Print the results in a readable way
Hints
Start with empty lists/dicts
Use loops and if conditions
(Optional / Advanced) Use Python list comprehension / generator syntax
# Your turn...
Exercise 4#
Concepts: user-defined functions, importing packages
Scenario#
You want to apply a custom analysis to the patient data dictionary to get notified on patients which need a further check-up.
Tasks#
Write a function
check_patientwhich takes the parameterspatient_id,systolic_bp,temperaturethe funtion shall return a notification for a patient (with patient_id), if blood pressure ≥ 130 and temperature ≥ 38.0
the notification shall include the next appointment as a randomly selected day within the next month
Import and use the Python package datetime to generate the appointment day
Collect and print all notifications
# Your turn...