USING THE PYTHON LANGUAGE Write a program that asks the user to enter 3 integers
ID: 3167711 • Letter: U
Question
USING THE PYTHON LANGUAGE
Write a program that asks the user to enter 3 integers in non-decreasing order (you may assume the user complies). The program should then print Pair if exactly two of the numbers are the same; and it should print No otherwise.
For example, when the program is run, it might look like:
Enter three numbers in NON-DECREASING ORDER: 4 4 7
Pair
Here, 4 4 7 is user input, and everything else is output by the program. If the user had input 3 8 8, the program again would have printed out Pair; if the user had input 5 5 5 or 5 6 8, the program would have output No.
Explanation / Answer
print('Enter three numbers in Non Decreasing Order:')
x = [int(x) for x in input().split()] # take the input and splits it
if (x[0]==x[1] and x[0]!=x[2]) or (x[0]==x[2] and x[0]!=x[1]) or (x[1]==x[2] and x[0]!=x[1]):
print("Pair")
else:
print("Not a Pair")
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.