Write a python program to input three numbers and display the larger or smaller number. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a python program to input three numbers and display the larger or smaller number.

16th Aug 2021, 1:33 PM
Aditya Pradhan
Aditya Pradhan - avatar
2 Answers
0
Heres a simply illustrative way using if statements, you could do this lots of different ways including creating a list and sorting. n1 = float(input()) n2 = float(input()) n3 = float(input()) # Find largest if (n1 > n2) and (n1 > n3): large = n1 elif (n2 > n1) and (n2 > n3): large = n2 else: large = n3 # Find smallest if (n1 < n2) and (n1 < n3): small = n1 elif (n2 < n1) and (n2 < n3): small = n2 else: small = n3 print("The large number is", large, "\n") print("The small number is", small, "\n")
2nd Sep 2021, 11:52 AM
DavX
DavX - avatar
0
This is a simplier version converting to a list and using min/max. Still the above example is more illustrative on how to compare: n1 = float(input()) n2 = float(input()) n3 = float(input()) nlist = [n1, n2, n3] print("The large number is", max(nlist), "\n") print("The small number is", min(nlist), "\n")
2nd Sep 2021, 11:56 AM
DavX
DavX - avatar