Instagram
youtube
Facebook
Twitter

Python Lucky Number programme Codechef solution

Problem:

A chef buys a lottery ticket that has a 3-digit code associated with it. He thinks that the digit 7 is his lucky digit and brings him good luck. Chef will win some amount in the lottery if at least one of the digits of the ticket is 7. Given the three digits A, B, and C of the lottery ticket, tell whether Chef wins something or not.

Input Format

  • The first line will contain T, the number of test cases. Then the test cases follow.

  • Each test case contains a single line of input, three space-separated integers A, B, and C.

Output Format

For each test case, output in a single line the answer "YES" if Chef wins a positive amount with the lottery and "NO" if not.

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

  • 0<=A,B,C<=9

Sample Input:

3 
0 0 0
7 8 9
2 7 7

Sample Output:

NO 
YES 
YES

Explanation:

  • Test Case 1: Since no digit is equal to 7, Chef fails to win any amount in the lottery.

  • Test Case 2: Since the first digit is equal to 7, Chef will win some amount in the lottery.

  • Test Case 3: Since the second and third digits are equal to 7, Chef will win some amount in the lottery.

Solution:

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

for i in range(T):

    A, B, C = map(int, input(“Enter 3 numbers: “).split())
    
    if A == 7 or B == 7 or C == 7:
        print("YES")
    else:
        print("NO")

Steps to solve this problem:

  • Ask the user to enter the number of terms.

  • In the 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.

  • Now check if A is equal to 7, or if B is equal to 7, or if C is equal to 7, print YES." Otherwise print NO."