Home

Algorithim Homework

def calculate_y_values(x_values):
    y_values = []
    for i in x_values:
        y = 3 * (i + 2) - 4
        y_values.append(y)
    return y_values

x_values = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]

y_values = calculate_y_values(x_values)

print("x-values:", x_values)
print("y-values:", y_values)

x-values: [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
y-values: [-13, -10, -7, -4, -1, 2, 5, 8, 11, 14, 17]

Popcorn Hack 2


num1 = 20
num2 = num1 /2 
num3 = num2 * 10 + 3
print(num3)
103.0

Popcorn Hack 3


def perform_operations(a, b):
    addition = a + b
    subtraction = a - b
    multiplication = a * b
    division = a / b
    mod = (a * b) % (a / b)

    return addition, subtraction, multiplication, division, mod

num1 = 10
num2 = 5

add_result, sub_result, mul_result, div_result, mod_result = perform_operations(num1, num2)

print(f'Addition: {add_result}')
print(f'Subtraction: {sub_result}')
print(f'Multiplication: {mul_result}')
print(f'Division: {div_result}')
print(f'MOD: {mod_result}')

Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2.0
MOD: 0.0

Popcorn Hack 4


length = len("Muzaffer")
print(length)

concat = "Imaad " + "Muzaffer"
print (concat)

substring = concat[1:5]
print (substring)
8
Imaad Muzaffer
maa

Hw Hack


def fibonacci(n):
    if n < 0:
        return "Input should be a non-negative integer."
    elif n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        fib_2 = 0
        fib_1 = 1

        for i in range(2, n + 1):
            fib = fib_minus_1 + fib_2
            fib_2 = fib_1
            fib_minus_1 = fib

        return fib

nth_index = 7  
result = fibonacci(nth_index)
print(f"The {nth_index}th Fibonacci number is: {result}")

The 7th Fibonacci number is: 13
© 2024    •  Powered by Soopr   •  Theme  Moonwalk