This function adds up the numbers between zero in a string. For example ('25025') becomes 25+25. However, if I have a 0 at start and/or end of the string of the string argument being sent to test_string, it creates a space in the at the start/end of the list and won't compute. What can I add to this function to make it filter out both 0s and blank spaces?
def test_one(test_string):
test = test_string.split("0")
numbers=[int(x) for x in test]
print(sum(numbers))
test_one('2022022022')
test_one('02022020')
test_one('25025')
Aucun commentaire:
Enregistrer un commentaire