Menu iconMenu iconAlgorithms and Data Structures with Python
Algorithms and Data Structures with Python

Project 1: Basic Calculator

5. Adding Advanced Arithmetic Functions

While our calculator already handles basic arithmetic, let's add a few more advanced operations such as power, square root, and factorial.

import math

def power(x, y):
    return x ** y

def square_root(x):
    return math.sqrt(x)

def factorial(x):
    if x == 0:
        return 1
    return math.factorial(x)

5. Adding Advanced Arithmetic Functions

While our calculator already handles basic arithmetic, let's add a few more advanced operations such as power, square root, and factorial.

import math

def power(x, y):
    return x ** y

def square_root(x):
    return math.sqrt(x)

def factorial(x):
    if x == 0:
        return 1
    return math.factorial(x)

5. Adding Advanced Arithmetic Functions

While our calculator already handles basic arithmetic, let's add a few more advanced operations such as power, square root, and factorial.

import math

def power(x, y):
    return x ** y

def square_root(x):
    return math.sqrt(x)

def factorial(x):
    if x == 0:
        return 1
    return math.factorial(x)

5. Adding Advanced Arithmetic Functions

While our calculator already handles basic arithmetic, let's add a few more advanced operations such as power, square root, and factorial.

import math

def power(x, y):
    return x ** y

def square_root(x):
    return math.sqrt(x)

def factorial(x):
    if x == 0:
        return 1
    return math.factorial(x)