Lab 2.1 – Maximum and Minimum of Three Numbers (no built‑ins)
Score: 0.2
Task: Write a program that reads three numbers and prints their maximum and minimum without using max() and min() (to practice conditional statements).
📌 Algorithm
- Read three numbers from the user.
- Use
if/elif/elseto find the maximum by comparing each pair. - Use a similar approach to find the minimum.
- Print both results.
💻 Solution Code
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
# Find maximum
if a >= b and a >= c:
maximum = a
elif b >= a and b >= c:
maximum = b
else:
maximum = c
# Find minimum
if a <= b and a <= c:
minimum = a
elif b <= a and b <= c:
minimum = b
else:
minimum = c
print("Maximum:", maximum)
print("Minimum:", minimum)
📤 Expected Output
Enter first number: 5 Enter second number: 12 Enter third number: 8 Maximum: 12 Minimum: 5
📖 Step‑by‑Step Explanation
- Read three numbers from the user.
- Use
if/elif/elseto find the maximum by checking each possibility. - Use the same approach to find the minimum.
- Print both results.