📝 Python Programming Assignment 2
Topic: Functions with NumPy & Matplotlib
🔹 Instructions for Students:
● Write clean, modular code using functions only.
● Include comments explaining the purpose of each function.
● Include your name, roll number, and section on the title name.
● Colab Notebook with output screenshots.
● Use numpy, matplotlib, or custom functions wherever applicable.
🔹 Part A: Basic Functions (Q1 – Q6)
🏋♂️
Q1. Write a function welcome() that prints:
"Welcome to Python Fitness Tracker " Call the function 3 times.
Q2. Write a function bmi(weight, height) that returns the Body Mass Index (BMI).
Formula: BMI = weight / height**2
Example: print(bmi(68, 1.75))
Q3. Write a function calories_burned(duration, rate=10) that returns total calories as duration * rate.
Call the function once with one argument and once with both arguments.
Q4. Create a function heart_rate_stats(max_bpm, avg_bpm, resting_bpm) that returns:
● Heart Rate Reserve = max_bpm - resting_bpm
● Average Difference = avg_bpm - resting_bpm
Print both returned values separately.
Q5. Write a function workout_summary(name, duration, type='Cardio', calories=500) that prints:
"Amit completed 1.2 hours of Cardio and burned 500 calories." Call it using keyword arguments in
random order.
Q6. Create two functions:
● add_calories(c1, c2) that returns sum of calories.
● weekly_burn() that calls add_calories() 7 times for each day’s burn.
Print total burn.
🔹 Part B: Intermediate Functions (Q7 – Q13)
Q7. Write a function fitness_profile(name, weight, height, age) that prints all details.
Call it once using positional and once using keyword arguments.
Q8. Write a function total_calories(*args) that returns the sum of all given calorie values.
Example: print(total_calories(200, 300, 150, 400))
Q9. Define a function generate_profile(name, age, weight, height) that returns a dictionary with keys:
Name, Age, Weight, Height, BMI.
Q10. Create a global variable bonus = 100.
Define a function calorie_reward(burn) that adds bonus to burn.
Then redefine it using a local variable bonus = 200 and observe difference.
Q11. Write a function calculate_HRR(max_bpm, resting_bpm, intensity=0.7) that returns Heart Rate
Reserve zone.
Q12. Write a function daily_burns(calories_list) that prints burn for each day and returns total.
Q13. Define a function filter_high_calories(calories, threshold) that returns all values > threshold.
Use list comprehension inside.
🔹 Part C: Advanced Concepts (Q14 – Q20)
Q14. Create a lambda function for BMI:
bmi = lambda w, h: w / (h ** 2)
Print result for (70, 1.75).
Q15. Write a function square(n) and apply it using map() on [2,4,6,8].
Print squared results.
Q16. Write a function is_high_burn(x) that returns True if x > 1000.
Use filter() on list [800, 1200, 950, 1500, 700, 2000].
Q17. Write a recursive function sum_n(n) to return sum of first n natural numbers.
Call sum_n(100).
Q18. Write a recursive function factorial(n) to return n!
Call factorial(6).
Q19. Write a function mean_std(array) that returns mean and standard deviation using NumPy.
Test: import numpy as np
data = [Link]([10,20,30,40,50])
print(mean_std(data))
Q20. Write a function plot_workout(time, calories) that plots a line chart using Matplotlib with:
● X-axis = time
● Y-axis = calories
● Title = "Workout Efficiency Tracker"
🔹 Bonus Section (Q21 – Q25)
Q21. Write a function to return top 5 calorie burners from your dataset (Final_data.csv).
Q22. Write a function to calculate and print average heart rate by gender.
Q23. Write a function to visualize Calories_Burned vs Session_Duration for each Workout_Type using
Matplotlib.
Q24. Write a function to compute correlation between any two numeric columns (column names taken
from user input).
Q25. Write a function that creates and saves any Matplotlib plot as a PNG file automatically.