SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.selections
Exercise:
Programming Excercises
Question:8 | ISBN:978013274719 | Edition: 6

Question

(Sort three integers) Write a program that prompts the user to enter three integers and displays them in increasing order.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

SOURCE CODE:
# Enter three integers
print("Enter three integers: ")
# Enter the value of a
num1=eval(input())
# Enter the value of b
num2=eval(input())
# Enter the value of c
num3=eval(input())
# Compare the first number with the second and third number
if (num1 >= num2) and (num1 >= num3):
   largest = num1
# Compare the second number with the first and third number   
elif (num2 >= num1) and (num2 >= num3):
   largest = num2
else:
   largest = num3
#Compare the first number with the second and third number 
if (num1<=num2 and num1<=num3):
    smallest = num1
#Compare the second number with the first and third number    
elif (num2<=num1 and num2<=num3):
    smallest = num2
else:
    smallest = num3
# Checking middle number
middle = (num1 + num2 + num3) - largest - smallest
print(largest,middle,smallest)

OUTPUT:

Enter three integers:                                                                                                           
2                                                                                                                               
9                                                                                                                               
5                                                                                                                               
9 5 2  

 

0 0

Discussions

Post the discussion to improve the above solution.