def luck_check(s: str):
# your code here
if s.isdecimal():
if int(len(s) % 2) == 0:
left = sum([int(i) for i in list(s[:int(len(s) / 2)])])
right = sum(int(i) for i in list(s[int(len(s) / 2):]))
if left == right:
return True
else:
return False
else:
left = sum([int(i) for i in list(s[:int(len(s) / 2)])])
right = sum(int(i) for i in list(s[int(len(s) / 2) + 1:]))
if left == right:
return True
else:
return False
else:
return "invalid input"
if __name__ == '__main__':
assert luck_check('683179') == True
assert luck_check('683000') == False
assert luck_check('') == "invalid input"
assert luck_check('6F43E8') == "invalid input"
assert luck_check('17935') == True
def luck_check(string):
#your code here
if len(string)==0:
raise "invalid input"
for i in string:
if i not in {str(j) for j in range(10)}:
raise "invalid input"
if len(string)%2!=0:
return sum(map(int,string[:len(string)//2]))==sum(map(int,string[len(string)//2+1:]))
else:
return sum(map(int,string[:len(string)//2]))==sum(map(int,string[len(string)//2:]))
from typing import Union
def luck_check(s: str) -> Union[bool, str]:
# your code here
if not s.isdigit():
return "invalid input"
if len(s) % 2 == 0 and sum(int(i) for i in s[0:len(s) // 2]) == sum(int(i) for i in s[-1:len(s) // 2 - 1:-1]):
return True
elif len(s) % 2 != 0 and sum(int(i) for i in s[0:len(s) // 2]) == sum(int(i) for i in s[-1:len(s) // 2:-1]):
return True
return False
assert luck_check('683179') == True
assert luck_check('683000') == False
assert luck_check('') == "invalid input"
assert luck_check('6F43E8') == "invalid input"
assert luck_check('17935') == True