Random Averages
Write a program that asks the user for a low number and a high number. These will be the ranges for random numbers. The program should then generate four random numbers and add these numbers together to create a total. The average should then be calculated, and all information displayed to the user. The average should be displayed to two decimal places.
Enter the lowest range: 5 Enter the highest range: 100 The numbers are: 23 97 29 93 The average is 60.5
get the low range from user get the high range from user generate number 1 as integer between low and high range generate number 2 as integer between low and high range generate number 3 as integer between low and high range generate number 4 as integer between low and high range calculate total of all four numbers calculate the average print all four numbers print the average to two decimal places
import random
low = int(input("Enter the lowest range: "))
high = int(input("Enter the highest range: "))
num1 = random.randint(low, high)
num2 = random.randint(low, high)
num3 = random.randint(low, high)
num4 = random.randint(low, high)
total = num1 + num2 + num3 + num4
average = total / 4
print("The numbers are:", num1, num2, num3, num4)
print("The average is", round(average, 2))
# Get both numbers from the user
number1 = int(input("Enter the first number: "))
number2 = int(input("Enter the second number: "))
# Add the numbers together to create a total
total = number1 + number2
# Calculate the average using the following formula
average = total / 2
# Print out the following to the user
print("Average:", round(average, 2))
Extension
Extend the program so that the first random numbers range is 5 times bigger than the other three numbers.
Enter the lowest range: 5 Enter the highest range: 100 The numbers are: 432 46 45 80 The average is 150.75