-
Notifications
You must be signed in to change notification settings - Fork 0
/
arithmetic.py
83 lines (53 loc) · 1.7 KB
/
arithmetic.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""Math functions for calculator."""
def add(num1, num2):
"""Return the sum of the two inputs."""
return num1 + num2
def add_multiples(nums_to_add):
my_sum = 0
for num in nums_to_add:
my_sum += num
return my_sum
def subtract(num1, num2):
"""Return the second number subtracted from the first."""
return num1 - num2
def subtract_multiples(nums_to_subtract):
my_difference = nums_to_subtract[0]
for i in range(1, len(nums_to_subtract)):
my_difference -= nums_to_subtract[i]
return my_difference
def multiply(num1, num2):
"""Multiply the two inputs together."""
return num1 * num2
def multiply_multiples(nums_to_multiply):
my_product = 1
for num in nums_to_multiply:
my_product *= num
return my_product
def divide(num1, num2):
"""Divide the first input by the second, returning a floating point."""
if num2 == 0:
return "You can't divide by zero"
else:
return num1 / num2
def divide_multiples(nums_to_divide):
my_quotient = nums_to_divide[0]
for i in range(1, len(nums_to_divide)):
my_quotient /= nums_to_divide[i]
return my_quotient
def square(num1):
"""Return the square of the input."""
# Needs only one argument
return num1 * num1
def cube(num1):
"""Return the cube of the input."""
# Needs only one argument
return num1 * num1 * num1
def power(num1, num2):
"""Raise num1 to the power of num and return the value."""
return num1 ** num2 # ** = exponent operator
def mod(num1, num2):
"""Return the remainder of num / num2."""
if num2 == 0:
return "You can't divide by zero"
else:
return num1 % num2