-
Notifications
You must be signed in to change notification settings - Fork 0
/
18.py
26 lines (20 loc) · 774 Bytes
/
18.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
'''
Add, Subtract, Multiply or Divide?
Write a function that takes two numbers and returns if they should be added, subtracted, multiplied or divided to get 24.
If none of the operations can give 24, return None.
Notes:
Only integers are used as test input.
Numbers should be added, subtracted, divided or multiplied in the order they appear in the parameters.
The function should return either "added", "subtracted", "divided", "multiplied" or None.
'''
def operation(num1, num2):
if num1 + num2 == 24:
return 'added'
elif num1 - num2 == 24 or num2 - num1 == 24:
return 'subtracted'
elif num1 / num2 == 24 or num2 / num1 == 24:
return 'divided'
elif num1 * num2 == 24:
return 'multiplied'
else:
return None