Choose the op X58765


Statement
 

pdf   zip   main.py

html

Write a function choose_op(ls, op) that receives a list of positive integers and a string op. The string is one of "add", "mul", "cnt". It must return the result of adding together, multiplying together, or counting the digits of all the integers in the list, respectively.

Sample session
>>> choose_op([1, 5, 25, 50, 44, 33, 22], "add")
180
>>> choose_op([1, 5, 25, 50, 44, 33, 22], "mul")
199650000
>>> choose_op([1, 5, 25, 50, 44, 33, 22], "cnt")
12
Information
Author
José Luis Balcázar / Lluís Padró
Language
English
Official solutions
Python
User solutions
Python