Ad
Code
Diff
  • def add(string, option):
        even_list = []
        odd_list = []
        all_sum = 0
        for num in string:
            num = int(num)
            all_sum += num
            if num % 2 == 0:
                even_list.append(num)
            if num % 2 != 0:
                odd_list.append(num)
        if option == 0:
            return all_sum
        if option == 1:
            return sum(odd_list)
        if option == 2:
            return sum(even_list)
                
    • def add(string, option):
    • return 28 #total depending on the option
    • even_list = []
    • odd_list = []
    • all_sum = 0
    • for num in string:
    • num = int(num)
    • all_sum += num
    • if num % 2 == 0:
    • even_list.append(num)
    • if num % 2 != 0:
    • odd_list.append(num)
    • if option == 0:
    • return all_sum
    • if option == 1:
    • return sum(odd_list)
    • if option == 2:
    • return sum(even_list)