Ahaan

3.3 and 3.5 Homework

Hack 1 For 3.3

# Add two parameters
def add(a, b):
    return a + b

# Subtract two parameters
def subtract(a, b):
    return a - b

# Divide two parameters
def divide(a, b):
    if b != 0:
        return a / b
    else:
        return "Cannot divide by zero"

# Find the modulus of two parameters
def modulus(a, b):
    return a % b

# Raise parameter A to the power of parameter B
def power(a, b):
    return a ** b


# Testing Function
print(add(3, 4))          # 7
print(subtract(10, 3))    # 7
print(divide(10, 2))      # 5.0
print(modulus(10, 3))     # 1
print(power(2, 3))        # 8
7
7
5.0
1
8

Hack 2 For 3.3

 # Function to find a point on the graph of f(x) = 5x + 2
def point_on_graph(x):
    return 5 * x + 2


# Testing Hack 2 function
print(point_on_graph(1))  # 7 (since 5*1 + 2 = 7)
print(point_on_graph(2))  # 12 (since 5*2 + 2 = 12)

7
12

Hack 2 For 3.5

# In Python

# Defining the variables
is_raining = True
is_cold = False

# Expression 1 using De Morgan's Law
stay_inside_1 = not is_raining or not is_cold

# Expression 2 directly (already simplified by De Morgan's Law)
stay_inside_2 = not is_raining or not is_cold

# Print the results
print("Stay Inside (Expression 1):", stay_inside_1)  # Expected Output: True
print("Stay Inside (Expression 2):", stay_inside_2)  # Expected Output: True

Stay Inside (Expression 1): True
Stay Inside (Expression 2): True

Hack 1 For 3.5

def goOutside(temperature, isRaining):
    if temperature < 100 and isRaining:
        print("You should go outside, it's raining but not too hot.")
        return True
    elif temperature > 32 and not isRaining:
        print("You should go outside, it's not raining and not too cold.")
        return True
    else:
        print("You shouldn't go outside due to extreme weather conditions.")
        return False

# Example call to the function
goOutside(50, False)  # Adjust the temperature and isRaining values as needed

    
You should go outside, it's not raining and not too cold.





True
Scroll to top