-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_08.py
29 lines (27 loc) · 1.05 KB
/
task_08.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from functools import reduce
def multiply_numbers(*args):
if args:
new_list = []
for i in args:
if isinstance(i, str):
digits = [int(ch) for ch in i if ch.isdigit()]
if digits:
new_list.extend(digits)
elif isinstance(i, (float)):
lst = [int(j) for j in str(i) if j.isdigit()]
new_list.extend(lst)
elif isinstance(i, (int)):
new_list.append(i)
elif isinstance(i, (tuple, list, set)):
digits = [int(num) for num in i if isinstance(num, (int, float, str)) and str(num).isdigit()]
if digits:
new_list.extend(digits)
if new_list:
return reduce(lambda x,y: x*y, new_list)
return None
# print(multiply_numbers()) # => None
# print(multiply_numbers('ss')) # => None
# print(multiply_numbers('1234')) # => 24
# print(multiply_numbers('sssdd34')) # => 12
# print(multiply_numbers(2.3)) # => 6
# print(multiply_numbers([5, 6, 4])) # => 120