Computer Science

Given three numbers A, B and C, write a program to write their values in an ascending order. For example, if A = 12, B = 10, and C = 15, your program should print out:

Smallest number = 10
Next higher number = 12
Highest number = 15

Python

Python Control Flow

23 Likes

Answer

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

if a < b and a < c :
    small = a
    if b < c :
        middle = b
        large = c
    else :
        middle = c
        large = b
elif b < a and b < c :
    small = b
    if a < c :
        middle = a
        large = c
    else :
        middle = c
        large = a
else :
    small = c
    if a < b :
        middle = a
        large = b
    else :
        middle = b
        large = a


print("Smallest number =", small)
print("Next higher number =", middle)
print("Highest number =", large)

Output

Enter first number: 10
Enter second number: 5
Enter third number: 15
Smallest number = 5
Next higher number = 10
Highest number = 15

Answered By

11 Likes


Related Questions