Menu iconMenu icon
Algoritmos y Estructuras de Datos con Python

Proyecto 1: Calculadora Básica

6. Incorporación de Funciones Avanzadas

Ahora que hemos definido nuestras funciones avanzadas, vamos a agregarlas a nuestro bucle principal.

# ... previous code ...

print("Options:")
print("Enter 'add' for addition")
print("Enter 'subtract' for subtraction")
print("Enter 'multiply' for multiplication")
print("Enter 'divide' for division")
print("Enter 'power' for raising to a power")
print("Enter 'square_root' for square root")
print("Enter 'factorial' for factorial")
print("Enter 'quit' to end the program")

# ... previous code ...

    if user_input == 'power':
        x = float(input("Enter the base number: "))
        y = float(input("Enter the power: "))
        print(f"{x} raised to the power of {y} is {power(x, y)}")

    elif user_input == 'square_root':
        x = float(input("Enter the number: "))
        print(f"The square root of {x} is {square_root(x)}")

    elif user_input == 'factorial':
        x = int(input("Enter the number: "))
        if x < 0:
            print("Factorial is not defined for negative numbers!")
        else:
            print(f"The factorial of {x} is {factorial(x)}")

    # ... rest of the code ...

6. Incorporación de Funciones Avanzadas

Ahora que hemos definido nuestras funciones avanzadas, vamos a agregarlas a nuestro bucle principal.

# ... previous code ...

print("Options:")
print("Enter 'add' for addition")
print("Enter 'subtract' for subtraction")
print("Enter 'multiply' for multiplication")
print("Enter 'divide' for division")
print("Enter 'power' for raising to a power")
print("Enter 'square_root' for square root")
print("Enter 'factorial' for factorial")
print("Enter 'quit' to end the program")

# ... previous code ...

    if user_input == 'power':
        x = float(input("Enter the base number: "))
        y = float(input("Enter the power: "))
        print(f"{x} raised to the power of {y} is {power(x, y)}")

    elif user_input == 'square_root':
        x = float(input("Enter the number: "))
        print(f"The square root of {x} is {square_root(x)}")

    elif user_input == 'factorial':
        x = int(input("Enter the number: "))
        if x < 0:
            print("Factorial is not defined for negative numbers!")
        else:
            print(f"The factorial of {x} is {factorial(x)}")

    # ... rest of the code ...

6. Incorporación de Funciones Avanzadas

Ahora que hemos definido nuestras funciones avanzadas, vamos a agregarlas a nuestro bucle principal.

# ... previous code ...

print("Options:")
print("Enter 'add' for addition")
print("Enter 'subtract' for subtraction")
print("Enter 'multiply' for multiplication")
print("Enter 'divide' for division")
print("Enter 'power' for raising to a power")
print("Enter 'square_root' for square root")
print("Enter 'factorial' for factorial")
print("Enter 'quit' to end the program")

# ... previous code ...

    if user_input == 'power':
        x = float(input("Enter the base number: "))
        y = float(input("Enter the power: "))
        print(f"{x} raised to the power of {y} is {power(x, y)}")

    elif user_input == 'square_root':
        x = float(input("Enter the number: "))
        print(f"The square root of {x} is {square_root(x)}")

    elif user_input == 'factorial':
        x = int(input("Enter the number: "))
        if x < 0:
            print("Factorial is not defined for negative numbers!")
        else:
            print(f"The factorial of {x} is {factorial(x)}")

    # ... rest of the code ...

6. Incorporación de Funciones Avanzadas

Ahora que hemos definido nuestras funciones avanzadas, vamos a agregarlas a nuestro bucle principal.

# ... previous code ...

print("Options:")
print("Enter 'add' for addition")
print("Enter 'subtract' for subtraction")
print("Enter 'multiply' for multiplication")
print("Enter 'divide' for division")
print("Enter 'power' for raising to a power")
print("Enter 'square_root' for square root")
print("Enter 'factorial' for factorial")
print("Enter 'quit' to end the program")

# ... previous code ...

    if user_input == 'power':
        x = float(input("Enter the base number: "))
        y = float(input("Enter the power: "))
        print(f"{x} raised to the power of {y} is {power(x, y)}")

    elif user_input == 'square_root':
        x = float(input("Enter the number: "))
        print(f"The square root of {x} is {square_root(x)}")

    elif user_input == 'factorial':
        x = int(input("Enter the number: "))
        if x < 0:
            print("Factorial is not defined for negative numbers!")
        else:
            print(f"The factorial of {x} is {factorial(x)}")

    # ... rest of the code ...