-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lucky ticket .py
47 lines (29 loc) · 1.13 KB
/
Lucky ticket .py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Indexes
Lucky ticket
Hard
Lucky tickets are a kind of mathematical entertainment. A ticket is considered lucky if the sum of the first 3 digits equals the sum of the last 3 digits of the ticket number.
You are supposed to write a program that checks whether the two sums are equal. The code snippet below displays "Lucky" if they are and "Ordinary" if they are not.
However, some parts of the code are missing. Fill in the blanks to make it work!
Input: a string of 6 digits.
Output: either "Lucky" or "Ordinary" (without quotes).
Make sure that you are NOT concatenating strings. To do this, convert each digit in the ticket number to an integer. Don't forget to use proper indices.
Sample Input 1:
090234
Sample Output 1:
Lucky
Sample Input 2:
123456
Sample Output 2:
Ordinary
"""
# Save the input in this variable
ticket = input()
# Add up the digits for each half
half_1 = [int(ticket[0]) + int(ticket[1]) + int(ticket[2])]
half_2 = [int(ticket[3]) + int(ticket[4]) + int(ticket[5])]
# Thanks to you, this code will work
if half_1 == half_2:
print("Lucky")
else:
print("Ordinary")