Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions 6-functions/31_calculator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Calculator 🔢
# Codédex

import math

def add(a, b):
return a + b

Expand All @@ -16,8 +18,24 @@ def divide(a, b):
def exp(a, b):
return a ** b

def modulus(a, b):
return a % b

def floor_divide(a, b):
if b == 0:
return "Error! Division by zero."
return a // b

def square_root(a):
if a < 0:
return "Error! Negative number."
return math.sqrt(a)

print(add(3, 5))
print(subtract(7, 2))
print(multiply(4, 8))
print(divide(9, 3))
print(exp(2, 3))
print(modulus(10, 3))
print(floor_divide(10, 3))
print(square_root(16))