Instagram
youtube
Facebook
Twitter

Python best of two program Codechef solution

Python best of two program Codechef solution

Problem

Chef took an examination twice. In the first attempt, he scored X marks, while in the second attempt, he scored Y marks. According to the rules of the examination, the best score out of the two attempts will be considered the final score.

Determine the final score for the Chef.

Input Format

  • The first line contains a single integer T—tthe number of test cases. Then the test cases follow.
  • The first line of each test case contains two integers, X and Y—tthe marks scored by Chef in the first attempt and second attempt, respectively.

Output Format

For each test case, output the final score of Chef in the examination.

Constraints:

  • 1≤T≤1000
  • 0<=X,Y<=100

Sample Input:

40 60 

67 55 

50 50 

1 100

Sample Output:

60 

67 

50 

100

Explanation:

Test Case 1: The best score out of the two attempts is 60.

Test Case 2: The best score out of the two attempts is 67.

Test Case 3: The best score out of the two attempts is 50.

Solution:

for i in range(int(input(“Enter the number of terms needed: “))):

    a,b=map(int,input(“Enter the marks scored by Chef in the first attempt and second attempt: “).split())

    if(a>b):

        print(a)

    else:

        print(b)

 

        Steps to solve this problem:

  1. Ask the user to enter a number of terms.
  2. In the loop, ask the user to enter the marks scored by Chef in the first and second attempts, and using the map() function, get iterator objects and store them in a and b,  respectively.
  3. Check if a is greater than b, then print the value of a. Otherwise, print the value of b.