Second Max of Three Number solution do it using python 3
Write a program that accepts sets of three numbers, and prints the second-maximum number among the three.
Input
- First line contains the number of triples, N.
- The next N lines which follow each have three space separated integers.
Output
For each of the N triples, output one new line which contains the second-maximum integer among the three.
Constraints
- 1 ≤ N ≤ 6
- 1 ≤ every integer ≤ 10000
- The three integers in a single triplet are all distinct. That is, no two of them are equal.
Sample 1:
Input:
1 2 3
input:
10 15 5
Output: 2
10
Program:
x,y,z=input().split()
l=[int(x),int(y),int(z)]
print(sorted(l)[1])
or
x,y,z=map(int,input().split())
a=max(x,y,z)
b=min(x,y,z)
if x<a and x>b:
print(x)
elif y<a and y>b:
print(y)
elif z<a and z>b:
print(z)
0 Comments