Instagram
youtube
Facebook
Twitter

Python Perfect Trio program Codechef solution

  1. Python Perfect Trio programme Codechef solution

Problem

A chef defines a group of three friends as a perfect group if the age of one person is equal to the sum of the ages of the remaining two people.

Given that the ages of three people in a group are A,B, and C, respectively, find whether the group is perfect.

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of three space-separated integers A,B, and C—the ages of the three members of the group.

Output Format

For each test case, output on a new line, yes if the group is perfect, and no otherwise.

You may print each character in uppercase or lowercase. For example, the strings YES, yes, Yes, and yes are considered identical.

Constraints:

  • 1≤T≤200
  • 1<=A,B,C<=100

Sample Input:

10 20 30

23 51 17

44 21 23

30 30 30

Sample Output:

YES 

NO 

YES 

NO

Explanation:

Test case 1: The sum of the ages of the first and second persons is equal to that of the third person. Thus, the group is perfect.

Test case 2: There is no member in the group such that the age of one person is equal to the sum of the ages of the remaining two people. Thus, the group is not perfect.

Test case 3: The sum of the ages of the second and third persons is equal to that of the first person. Thus, the group is perfect.

Test case 4: There is no member in the group such that the age of one person is equal to the sum of the ages of the remaining two people. Thus, the group is not perfect.

Solution:

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

    a,b,c = map(int,input(“Enter age of 3 members of a group: “).split())

    if(a==b+c):

        print("YES")

    elif(b==a+c):

        print("YES")

    elif(c==b+a):

        print("YES")

    else:

        print("NO")

 

          Steps to solve this problem:

  1. Ask the user to enter a number of terms.
  2. In a loop, ask the user to enter the ages of three members of a group and use the map() function. Get iterator objects and store them in a, b, and c, respectively.
  3. Check if a is equal to (b+c), then print "YES".
  4. Now check if b is equal to (a+c), then print "YES".
  5. Again, check if c is equal to (b+a), then print "YES".
  6. If all the above conditions evaluate to false, then print "NO".