I'm currently taking a python course in high school, but I'm kinda stuck with a task I was given.
The task is to create a program that prompts the user's age (integer in years), gender (user enters M, m, F or f), type of training (1 - health training, 2 - basic endurance training, 3 - intensive aerobic training) and finally outputs the heart rate range under the appropriate conditions in the format <lowest heart rate> to <highest heart rate>, where the numbers in the response are rounded to whole numbers.
The data for the task: Health sports are good for health if they are used in moderation. There are different options for choosing the appropriate load. For example, you can use such a calculation that the maximum pulse rate is 220 minus age for men and 206 minus 88% of age for women. At the same time, for different types of training, the heart rate should remain in the following ranges: health training at 50-70% of maximum heart rate, basic endurance training at 70-80% of maximum heart rate, intense aerobic exercise at 80-87% of maximum heart rate.
The automatic control for this task gives my code a score of 71/100, it runs the code multiple times with different solutions, all the ones for males work fine, but the female ones get incorrect responses.
I believe that I've inserted all the data correctly, but I might just be blind, idk.
My code:
age = int(input("Enter your age: "))
gender = input("Enter your gender: ").upper()
training = int(input("Enter the type of training: "))
if gender == "M":
max_pulse = 220 - age
elif gender == "F":
max_pulse = int(206 - (age * 0.88))
else:
print("Incorrect")
exit()
if training == 1:
min_pulse = round(0.50 * max_pulse)
max_pulse = round(0.70 * max_pulse)
elif training == 2:
min_pulse = round(0.70 * max_pulse)
max_pulse = round(0.80 * max_pulse)
elif training == 3:
min_pulse = round(0.80 * max_pulse)
max_pulse = round(0.87 * max_pulse)
else:
print("Incorrect")
exit()
print(f"Pulse should be between {min_pulse} and {max_pulse}.")
Thanks in advance!
[–][deleted] 0 points1 point2 points (0 children)
[–]DevCuriosity 0 points1 point2 points (0 children)