1def no_it_isnt(vals):
2 res = []
3 for val in vals:
4 current_type = type(val)
5
6 if current_type in (int, float):
7 res.append(-val)
8 elif current_type is bool:
9 res.append(not val)
10 elif current_type is str:
11 res.append(val[::-1])
12 else:
13 raise Exception("Function doesn't work with the given type.")
14 return res[::-1]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.000s
OK
f | 1 | def no_it_isnt(vals): | f | 1 | def no_it_isnt(vals): |
2 | res = [] | 2 | res = [] | ||
3 | for val in vals: | 3 | for val in vals: | ||
4 | current_type = type(val) | 4 | current_type = type(val) | ||
5 | 5 | ||||
t | 6 | if current_type is int or current_type is float: | t | 6 | if current_type in (int, float): |
7 | res.append(-val) | 7 | res.append(-val) | ||
8 | elif current_type is bool: | 8 | elif current_type is bool: | ||
9 | res.append(not val) | 9 | res.append(not val) | ||
10 | elif current_type is str: | 10 | elif current_type is str: | ||
11 | res.append(val[::-1]) | 11 | res.append(val[::-1]) | ||
12 | else: | 12 | else: | ||
13 | raise Exception("Function doesn't work with the given type.") | 13 | raise Exception("Function doesn't work with the given type.") | ||
14 | return res[::-1] | 14 | return res[::-1] |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|