forked from talk2francis/python-javascript.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScientific_calculator.py
More file actions
45 lines (36 loc) · 822 Bytes
/
Copy pathScientific_calculator.py
File metadata and controls
45 lines (36 loc) · 822 Bytes
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
import math
def add(x, y):
"""Adds two numbers."""
return x + y
def subtract(x, y):
"""Subtracts two numbers."""
return x - y
def multiply(x, y):
"""Multiplies two numbers."""
return x * y
def divide(x, y):
"""Divides two numbers."""
return x / y
def power(x, y):
"""Raises a number to a power."""
return x ** y
def square_root(x):
"""Returns the square root of a number."""
return math.sqrt(x)
def factorial(x):
"""Returns the factorial of a number."""
if x == 0:
return 1
else:
return x * factorial(x - 1)
def main():
"""Prints the results of some mathematical operations."""
print(add(1, 2))
print(subtract(10, 5))
print(multiply(2, 3))
print(divide(10, 2))
print(power(2, 3))
print(square_root(16))
print(factorial(5))
if __name__ == "__main__":
main()