Skip to the content.

3.6.teamteach_ipynb_2_

# Step 1: Add a variable that represents temperature
temperature = 66  # You can change this value to test different conditions

# Step 2: Check if it’s a hot day
if temperature >= 80:
    print("It's a hot day")
# Step 3: Else if it's a warm day
elif 60 <= temperature <= 79:
    print("It's a warm day")
# Step 4: Otherwise, print it's a cold day
else:
    print("It's a cold day")

It's a warm day

3.6.2 Popcorn Hack

%%js 
let score = 30;

if (score >= 60) {
    console.log("You passed!");
} else {
    console.log("You didn't pass.");
}
<IPython.core.display.Javascript object>

3.6.3 Homework:

Hack 1

def check_odd_even(number): 

    if number % 2 == 0:
        print("Even")
    else:
        print("Odd")

print(check_odd_even(7))
print(check_odd_even(10))

Odd
None
Even
None

Hack 2

def is_leap_year(year):

    if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
        print("Leap Year")
    else:
        print("Not a Leap Year")

print(is_leap_year(2020))
print(is_leap_year(2013))
Leap Year
None
Not a Leap Year
None

Hack 3

def temperature_range(temperature):
    if temperature <= 60:
        print("Cold")
    elif 60 <= temperature <= 80:
        print("Warm")
    else:
        print("Hot")

print(temperature_range(90))
print(temperature_range(66))
Hot
None
Warm
None

3.6.4 Homework Hacks

Hack 1:

%%js 
function checkVotingEligibility(age) {
    if (age >= 18) {
        return "You are eligible to vote!";
    } else {
        return "You are not eligible to vote yet.";
    }
}

console.log(checkVotingEligibility(20));  
console.log(checkVotingEligibility(16));

<IPython.core.display.Javascript object>

Hack 2:

%%js 
function getGrade(score) {
    if (score >= 90) {
        return "Grade: A";
    } else if (score >= 80) {
        return "Grade: B";
    } else if (score >= 70) {
        return "Grade: C";
    } else {
        return "Grade: F";
    }
}

console.log(getGrade(95));  
console.log(getGrade(85)); 

Hack 3:

function convertTemperature(value,scale) {
    if (scale === "C") {
        let fahrenheit = (value * 9/5) + 32;
        return fahrenheit + "°F"; 
    } else if (scale === "F") {
        let celsius = (value-32) * 5/9;
        return celsius.toFixed(2) + "°C";
    } else {
        return "Error: Invalid scale. Use 'C' for Celsius or 'F' for Fahrenheit.";
    }
}

console.log(convertTemperature(30, "C"));  
console.log(convertTemperature(86, "F"));