Untitled
unknown
plain_text
2 years ago
1.3 kB
9
Indexable
import random
def calculate_closest_average(num1, num2):
average = (num1 + num2) / 2
return int(average) # Convert average to an integer
def generate_options(correct_avg):
options = [correct_avg]
while len(options) < 3:
random_avg = correct_avg + random.randint(-10, 10)
if random_avg != correct_avg and random_avg not in options:
options.append(random_avg)
random.shuffle(options)
return options
def main():
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
correct_avg = calculate_closest_average(num1, num2)
options = generate_options(correct_avg)
print(f"Number 1: {num1}")
print(f"Number 2: {num2}")
print("Choose the option with the closest average:")
for i, option in enumerate(options):
print(f"{i+1}. {option}")
user_choice = input("Your choice (1, 2, or 3): ")
if user_choice.isdigit() and 1 <= int(user_choice) <= 3:
user_choice = int(user_choice)
if options[user_choice - 1] == correct_avg:
print("Congratulations! You chose the correct option.")
else:
print(f"Sorry, the correct answer was {correct_avg}.")
else:
print("Invalid input. Please choose a number between 1 and 3.")
if __name__ == "__main__":
main()
Editor is loading...