Python Favourite Number program Codechef solution
Python Favourite Number program Codechef solution
Problem
- Alice likes numbers that are even and are a multiple of 7.
- Bob likes numbers that are odd and are a multiple of 9.
Alice, Bob, and Charlie find the number A.
- If Alice likes A, she takes home the number.
- If Bob likes A, he takes home the number.
- If both Alice and Bob don't like the number, Charlie takes it home.
Given A, find out who takes it home.
Note: You can prove that there is no integer A such that both Alice and Bob like it.
Input Format
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single integer, A.
Output Format
For each test case, output on a new line who takes the number home: "Alice", "Bob", or "Charlie".
You may print each character in uppercase or lowercase. For example, Alice, Alice, LiCe, and Alice are all considered identical.
Constraints
- 1≤T≤100
- 1≤X<K≤1000
Sample Input:
8
7
14
21
18
27
63
126
8
Sample Output:
Charlie
Alice
Charlie
Charlie
Bob
Bob
Alice
Charlie
Explanation:
Testcase 1: 7 is not even, hence Alice doesn't like it. It is odd, but it isn't a multiple of 9. Hence, Bob doesn't like it. Therefore, Charlie takes it home.
Testcase 2: 14 is even and a multiple of 7. Therefore, Alice likes it and takes it home.
Testcase 3: 21 is not even, hence Alice doesn't like it. It is odd, but it isn't a multiple of 9. Hence, Bob doesn't like it. Therefore, Charlie takes it home.
Testcase 4: 18 is even but not a multiple of 7, hence Alice doesn't like it. It is not odd, and hence Bob doesn't like it. Therefore, Charlie takes it home.
Testcase 5: 27 is odd and a multiple of 9. Therefore, Bob likes it and takes it home.
Testcase 6: 63 is odd and a multiple of 9. Therefore, Bob likes it and takes it home.
Testcase 7: 126 is even and a multiple of 7. Therefore, Alice likes it and takes it home.
Testcase 8: 8 is even but not a multiple of 7, hence Alice doesn't like it. It is not odd, and hence Bob doesn't like it. Therefore, Charlie takes it home.
Solution:
n=int(input(“Enter the number of terms: “)) for i in range(n): a=int(input(“Enter any number: “)) if a%2==0 and a%7==0: print("Alice") elif a%2==1 and a%9==0: print("Bob") else: print("Charlie") |
Steps to solve this problem:
- Ask the user to enter the number of terms and store it in the variable n.
- In the loop, ask the user to enter any number and store it in the variable a.
- Check if a%2 and a%7 are equal to 0, then print "Alice".
- Again, check if a%2 is equal to 1 and a%9 is equal to 0, then print "Bob".
- Otherwise, print "Charlie".