Instagram
youtube
Facebook
Twitter

Python Age limit program Codechef solution

           Python Age limit programme Codechef solution

           Problem

The chef wants to appear in a competitive exam. To take the exam, there are the following requirements:

  • The minimum age limit is X (i.e., Age should be greater than or equal to X).
  • Age should be strictly less than Y.

The chef's current Age is A. Find out whether he is currently eligible to take the exam or not.

          Input Format

  • The first line will contain T, the number of test cases. Then the test cases follow.
  • Each test case consists of a single line of input containing the three integers X,Y, and A as mentioned in the statement.

          Output Format

For each test case, output YES if Chef is eligible to give the exam; NO otherwise.

You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical).

Constraints:

  • 1≤T≤1000
  • 20<=X<Y<=40
  • 10<=A<=50

Sample Input:

21 34 30

25 31 31

22 29 25

20 40 15

28 29 28

Sample Output:

YES 

NO 

YES 

NO 

YES

           Explanation:

Test case 1: The age of the chef is 30. His age satisfies the minimum age limit of 30. Also, it is less than the upper limit of 30–34. Thus, Chef is eligible to take the exam.

Test case 2: The age of the chef is 31. His age satisfies the minimum age limit of 325. But, it is not less than the upper limit as 31≮31. Thus, Chef is not eligible to take the exam.

Test case 3: The age of the chef is 25. His age satisfies the minimum age limit of 25. Also, it is less than the upper limit of 25–29. Thus, Chef is eligible to take the exam.

Test case 4: The age of the chef is 15. His age does not satisfy the minimum age limit of 15–20. Thus, Chef is not eligible to take the exam.

Solution:

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

for i in range(t):

    x,y,a=input(“Enter Minimum age, Maximum age and chef’s current age: “).split()

    #print(x,y,a)

    x=int(x)

    y=int(y)

    a=int(a)

    if(a>=x and a<y):

        print("YES")

    else:

        print("NO")

Steps to solve this problem:

  1. Ask the user to enter the number of terms.
  2. In the loop, ask the user to enter the minimum age, Maximum age, and chef’s current age.
  3. Using the int() function, convert them into int types.
  4. Check if a is greater than x and a is less than y, then print "YES". Otherwise, print NO."