Instagram
youtube
Facebook
Twitter

Python Maximum of Three Numbers program Codechef solution

Python Maximum of the Three Numbers program Codechef solution

           Problem

Write a program that accepts sets of three integers and prints the maximum among the three. 

Input

  • The first line contains the number of triples, N.
  • The next N lines that follow each have three space-separated integers.

Output

For each of the N triples, output one new line that contains the maximum integer among the three.

Constraints

  • 1<=N<=20
  • 1<=every integer<=1000000

Sample Input:

3

1 2 3

10 5 1

100 999 500

Sample Output:

3

10

999

Solution:

try:

    t=int(input(“Enter the number of terms: “))

    while(t):

        a,b,c=map(int, input(“Enter 3 numbers: “ ).split())

        if(a>b and a>c):

            print(a)

        elif(b>c and b>a):

            print(b)

        else:

            print(c)

        t-=1

except:

    pass

 

Steps to solve this problem:

  1. In the try block, ask the user to enter a number of terms and store them in
  2. In the while loop, ask the user to enter 3 numbers, and using the map() function, get iterator objects and store them in a, b, and c, respectively.
  3. Check if a is greater than b and c, then print the value of a.
  4. If the above condition equates to false, then check if b is greater than c and a, and then print the value of b.
  5. Otherwise, print the value of c.
  6. Decrease the value of t by 1.
  7. In the except block, we just left it empty, so we used the pass statement in it.