Answer:
In Python:
nums = []
for i in range(5):
num = int(input("Num: "))
nums.append(num)
print("1 - Smallest")
print("2 - Largest")
print("3 - Sum")
print("4 - Average")
menu = int(input("Select menu: "))
if menu == 1:
print("Smallest: ",min(nums))
elif menu == 2:
print("Largest: ",max(nums))
elif menu == 3:
isum = 0
for i in range(5):
isum+=nums[i]
print("Sum: ",isum)
elif menu == 4:
isum = 0
for i in range(5):
isum+=nums[i]
print("Average: ",isum/5)
else:
print("Invalid Menu Selected")
Step-by-step explanation:
This program uses a list to get inputs for the 5 numbers
Here, the list is initialized
nums = []
This iterates from 1 to 5
for i in range(5):
This gets input for the 5 numbers
num = int(input("Num: "))
This appends each number to the list
nums.append(num)
The next 4 lines represents the menu
print("1 - Smallest")
print("2 - Largest")
print("3 - Sum")
print("4 - Average")
This prompts the user for menu
menu = int(input("Select menu: "))
If menu is 1, print the smallest
if menu == 1:
print("Smallest: ",min(nums))
If menu is 2, print the largest
elif menu == 2:
print("Largest: ",max(nums))
If menu is 3, calculate and print the sum of all inputs
elif menu == 3:
isum = 0
for i in range(5):
isum+=nums[i]
print("Sum: ",isum)
If menu is 4, calculate and print the average of all inputs
elif menu == 4:
isum = 0
for i in range(5):
isum+=nums[i]
print("Average: ",isum/5)
If menu is not 1 to 4, then print invalid menu
else:
print("Invalid Menu Selected")