Sum Mixed Values
Real data often arrives in a messy mix: some numbers are already integers, while others are stored as strings. Write sum_mix, which takes a list arr, converts every element to an integer, and returns the total sum. The strings inside the list contain only numbers, so they can be converted safely.
Примеры
Ввод
[9, 3, "7", "3"]Вывод
22Ввод
["5", "0", 9, 3, 2, 1, "9", 6, 7]Вывод
42Ввод
["3", 6, 6, 0, "5", 8, 5, "6", 2, "0"]Вывод
41Нужно реализовать
def sum_mix(arr: list) -> int:
Теги
arraystringsmath
Kirjaudu sisään nähdäksesi palautushistorian
Kirjaudu sisäänKirjaudu sisään käyttääksesi tekoälymentoria
Kirjaudu sisäänVisible tests
1
Input
[9,3,"7","3"]Expected
222
Input
["5","0",9,3,2,1,"9",6,7]Expected
423
Input
["3",6,6,0,"5",8,5,"6",2,"0"]Expected
414
Input
["1","5","8",8,9,9,2,"3"]Expected
455
Input
[8,0,0,8,5,7,2,3,7,8,6,7,"1"]Expected
626
Input
[9]Expected
9Focus radio
Paused · SomaFM · Fluid