Write a program that prints minimum and maximum of five numbers entered by the user.
Question
Write a program that prints minimum and maximum of five numbers entered by the user.
✨ Free AI Tools for You
Powered by Chatterbot AI
Answer
Here is a Python program that reads five numbers from the user and then prints the minimum and maximum of those numbers:
# Program to find the minimum and maximum of five numbers
# Taking input from the user
numbers = []
for i in range(5):
num = float(input(f"Enter number {i+1}: "))
numbers.append(num)
# Finding minimum and maximum
min_num = min(numbers)
max_num = max(numbers)
# Printing the results
print("The minimum number is:", min_num)
print("The maximum number is:", max_num)
Key Points:
Input Handling: The program uses a loop to collect five numbers from the user.
Minimum and Maximum Functions: The
min()
andmax()
functions are used to find the minimum and maximum numbers, respectively.Output: Finally, it prints the minimum and maximum numbers.
This program ensures that we correctly identify the smallest and largest numbers from a set of five user-provided inputs.
India's 1st AI Doubt Solver for CBSE, JEE, and NEET
Ask a Question for Freeand then it's just ₹212 a month