Skip to the content.

3.5 Homework

Hack 1

Hack 1 (Python)

# Function to determine to go outside
def should_go_outside(temperature, is_raining):
    if temperature < 100 and is_raining:
        return True
    elif temperature > 32 and not is_raining:
        return True
    else:
        return False

# Example Output
print(should_go_outside(85, True))  # True
print(should_go_outside(50, False)) # True
print(should_go_outside(100, True)) # False
print(should_go_outside(30, False)) # False
True
True
False
False

Hack 1 (JavaScript)

// Function to determine to go outside
function shouldGoOutside(temperature, isRaining) {
    if (temperature < 100 && isRaining) {
        return true;
    } else if (temperature > 32 && !isRaining) {
        return true;
    } else {
        return false;
    }
}

// Example Output
console.log(shouldGoOutside(85, true));  // Output: true
console.log(shouldGoOutside(50, false)); // Output: true
console.log(shouldGoOutside(100, true)); // Output: false
console.log(shouldGoOutside(30, false)); // Output: false

Hack 2

Hack 2 (Python)

# Simplified Expression 1
stay_inside = not is_raining or not is_cold

# Simplified Expression 2
stay_inside = not is_raining and not is_cold

Hack 2 (JavaScript)

// Simplified Expression 1
let stayInside = !isRaining || !isCold;

// Simplified Expression 2
let stayInside = !isRaining && !isCold;