Amrivero-hub / Power_projects

Amazing Python Collection
0 stars 0 forks source link

Improvement variables name #1

Open Amrivero-hub opened 7 months ago

Amrivero-hub commented 7 months ago

Let’s improve the clarity of the triathlon program by renaming variables.

Amrivero-hub commented 7 months ago

def calculate_total_time(swimming_time, cycling_time, running_time): """ Calculates the total time taken to complete the triathlon.

Args:
    swimming_time (float): Time taken for swimming (in minutes).
    cycling_time (float): Time taken for cycling (in minutes).
    running_time (float): Time taken for running (in minutes).

Returns:
    float: Total time in minutes.
"""
return swimming_time + cycling_time + running_time

Get input from the user.

swimming_time = float(input("Enter the time for swimming (in minutes):")) cycling_time = float(input("Enter the time for cycling (in minutes):")) running_time = float(input("Enter the time for running (in minutes):"))

Calculate the total time using the method.

total_time = calculate_total_time(swimming_time, cycling_time, running_time)

Determine the award based on the total time.

if total_time <= 100: participant_award = "Provincial Colours" # Within the qualifying time (0 - 100 minutes) elif total_time <= 105: participant_award = "Provincial Half Colours" # Within 5 minutes of the qualifying time (101 - 105 minutes) elif total_time <= 110: participant_award = "Provincial Scroll" # Within 10 minutes of the qualifying time (106 - 110 minutes) else: participant_award = "No award"

Display the award to the participant.

print(f"The award that the participant will receive is {participant_award}.")

Amrivero-hub commented 7 months ago

In this updated version:

I renamed swimming, cycling, and running to swimming_time, cycling_time, and running_time, respectively, for clarity. I also renamed award to participant_award to make its purpose more explicit.