write a python code to take in 3 test inputs and give me the best two average out of three
- User
write a python code to take in 3 test inputs and give me the best two average out of three
- Assistant
Here is a Python code that takes in three test inputs and calculates the average of each pair of tests. Then it returns the two averages with the highest values:
test_scores = [] for i in range(3): score = int(input(f"Enter test score {i+1}: ")) test_scores.append(score) averages = [] for i in range(3): for j in range(i+1, 3): avg = (test_scores[i] + test_scores[j]) / 2 averages.append(avg) averages.sort() best_averages = averages[-2:] print("The best two averages are:", best_averages)Example usage:
Enter test score 1: 85 Enter test score 2: 92 Enter test score 3: 78 The best two averages are: [88.5, 83.5]In this example, the three test inputs are 85, 92, and 78. The code calculates the average of each pair of tests: (85+92)/2 = 88.5, (85+78)/2 = 81.5, and (92+78)/2 = 85. Then it selects the two averages with the highest values, which are 88.5 and 85. The final result is 88.5 and 85.
- User
write a python code to take in 3 test inputs and give me the best two average out of three dont use array
- Assistant
Certainly! Here's a Python code that takes in three test inputs and calculates the average of each pair of tests. Then it returns the two averages with the highest values, without using an array:
# Input test scores score1 = int(input("Enter test score 1: ")) score2 = int(input("Enter test score 2: ")) score3 = int(input("Enter test score 3: ")) # Calculate averages avg1 = (score1 + score2) / 2 avg2 = (score1 + score3) / 2 avg3 = (score2 + score3) / 2 # Determine the best two averages best_avg1 = max(avg1, avg2, avg3) if best_avg1 == avg1: best_avg2 = max(avg2, avg3) elif best_avg1 == avg2: best_avg2 = max(avg1, avg3) else: best_avg2 = max(avg1, avg2) print("The best two averages are:", best_avg1, "and", best_avg2)Example usage:
Enter test score 1: 85 Enter test score 2: 92 Enter test score 3: 78 The best two averages are: 88.5 and 83.5In this example, the three test inputs are 85, 92, and 78. The code calculates the average of each pair of tests: (85+92)/2 = 88.5, (85+78)/2 = 81.5, and (92+78)/2 = 85. Then it determines the best two averages by comparing them. The final result is 88.5 and 83.5.