Lucky Ticket Number
Programming Basics · Python
TASK
Problem
Given a six-digit string (leading zero allowed), print `LUCKY` if the sum of first three digits equals the sum of last three.
EXAMPLE
Example
123321
LUCKY
LIMITS
Constraints
exactly 6 digits
LEARN
Theory for this problem
+
`input()` reads data entered by the user. The result of `input()` is initially a string. `int()` converts a numeric string into an integer. The `+` operator adds numbers. Comparison operators `==`, `!=`, `<`, `>`, `<=`, `>=` compare values and produce `True` or `False`. `if` checks a condition and runs its block when the condition is true. `else` runs when the corresponding `if` condition is false. Square brackets `[]` let you access an individual character in a string by its index. Indexing starts at zero. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** An `if` statement chooses a program branch from a Boolean condition. Comparisons produce `True` or `False`, and `elif` lets you test several mutually exclusive cases in order. The expression `'LUCKY'` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Read a string and convert each position with `int(s[i])`; no loop is needed.']
ANSWER
Solution
+
s = input()
a = int(s[0]) + int(s[1]) + int(s[2])
b = int(s[3]) + int(s[4]) + int(s[5])
if a == b:
print('LUCKY')
else:
print('NO')