Answer:
d = {}
while True:
name = input("Enter the name of the boat (Press Enter or q to stop): ")
if name == "" or name == "q":
break
time = int(input("Enter the time (in seconds): "))
d[name] = time
winner_name = min(d, key=d.get)
winner_time = min(d.values())
average_time = sum(d.values()) / len(d.values())
slowest_boat = max(d, key=d.get)
slowest_time = max(d.values())
print(f"Winner name: {winner_name} and its time: {winner_time}")
print(f"Average time: {average_time}")
print(f"Slowest boat: {slowest_boat} and its time: {slowest_time}")
Step-by-step explanation:
*The code is in Python.
Create an empty map(dictionary) to hold the values
Create a while loop. Inside the loop:
Ask the user to enter the name of the boat. Check if the user presses Enter or q, using if and break
Ask the user to enter the time
Insert these values as key-value pair to the map
When the loop is done:
Find the winner_name, the min() function finds the minimum value in a list. In this case, the key=d.get creates a list of the values in the map. The min(d, key=d.get) returns the key of the minimum value
Find the winner_time, min(d.values()) returns the minimum time in our map
Find the average time, the sum() function, returns the sum of the values in a list. In this case, sums all the values in the map. The len() function finds the count of the values. If we divide the sum of times entered by the count of the times entered, we get the average time
Find the slowest_time, the max() function returns the max of the value in a list. In this case, the maximum value is the slowest time
Print the results