def ticket_type(items): for item in items[:]: if sum(item[0:3]) == sum(item[4:]): print('Lucky ticket') elif sum(item[0:3]) == sum(item[4:]-1): print('drunk ticket') items = '122134' ticket_type(items) 

    1 answer 1

    1. sum does not support string.
    2. The cut says "take from the first to the second. Numbering from 0.

    It turns out you need to convert the slice into numbers and take the correct slice in the second case:

     def ticket_type(item): if type(item) is str and len(item) == 6: if sum(int(n) for n in item[0:3] if n.isdigit()) == sum(int(n) for n in item[3:] if n.isdigit()): print('Lucky ticket') else: print('drunk ticket') ticket_type('122134') # drunk ticket ticket_type('122221') # Lucky ticket 

    https://repl.it/EW6V/0