xah icon

Sample Problem 2: Are My Sums Right?

xah | PRO | 09/30/20 10:26:46 PM UTC (Edited) | 0 ⭐ | 422 👁️ | Never ⏰ | []
Python |

800 B

|

None

|

0 👍

/

0 👎

sample = input()
legend = []
 
while sample:
    if sample == '#':
        break
    
    for s in range(len(sample)):
        if sample[s] == '+':
            a = 'a'
            o = s
        elif sample[s] == '-':
            a = 'b'
            o = s
        elif sample[s] == '*':
            a = 'c'
            o = s
        elif sample[s] == '=':
            e = s
 
    if a == 'a':
        note = int(sample[:o]) + int(sample[o+1:e]) == int(sample[e+1:])
    elif a == 'b':
        note = int(sample[:o]) - int(sample[o+1:e]) == int(sample[e+1:])
    elif a == 'c':
        note = int(sample[:o]) * int(sample[o+1:e]) == int(sample[e+1:])
 
    if note:
        legend.append('Correct')
    else:
        legend.append('Wrong')
 
    sample = input()
 
for l in legend:
    print(l)

Comments