Q. Given three number A, B and C. Write a program to write their values in an ascending order.

For example A = 12, B = 10 and  C = 15, your program should print out :

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


You can understand by Watching video :-



Answer :-

a = int(input("Enter 1st number = "))
b = int(input("Enter 2nd number = "))
c = int(input("Enter 3rd number = "))
if a > b and b > c :
    max, mid, low = a, b, c
elif b > a and a > c :
    max, mid, low = b, a, c
elif c > b and b > a :
    max, mid, low = c, b, a
elif c > b and c > a and a > b :
    max, mid, low = c, a, b
elif b > c and b > a and a < c :
    max, mid, low = b, c, a
elif a > b and a > c and b < c :
    x, mid, low = a, c, b

print("Smallest number :- ",low)
print("Next higher number :- ",mid)
print("Highest  number :- ",max)

Output :-

Enter 1st number = 12
Enter 2nd number = 10
Enter 3rd number = 15
Smallest number :-  10
Next higher number :-  12
Highest  number :-  15

>>> 

Enter 1st number = 5
Enter 2nd number = 9
Enter 3rd number = 4
Smallest number :-  4
Next higher number :-  5
Highest  number :-  9

>>>

4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post