Skip to the content.

3.6 HW

3.6 HW and Popcorn Hacks

Tri 1 Documentation

#Popcorn Hack #1
# Step 1: Add a variable that represents temperature
temperature = 60  # 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: If it’s not a hot day, check if it’s a warm day using an elif statement
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
// Popcorn Hack #2
let score = 85;

if (score >= 60) {
    console.log("You passed!");
}
// Add an else statement to say you failed if the score is less than 60
else { 
    console.log("You failed.");
}
# Homework Hack 1 Python: Even or Odd

def check_odd_even(number):
    if number % 2 == 0:
        return (number, "is even.")
    else:
        return(number, "is odd")
print(check_odd_even(5))
print(check_odd_even(27))
print(check_odd_even(20))
print(check_odd_even(10))

# Homework Hack 2 Python: Leap Year Checker
def check_leap_year(year):
    if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
        return (year, "is a leap year.")
    else:
        return(year, "isn't a leap year")
print(check_leap_year(2024))
print(check_leap_year(1998))
print(check_leap_year(2000))
print(check_leap_year(1678))

# Homework Hack 3 Python: Temperature Range Checker
def check_temp_range(temperature):
    if temperature >= 85:
        return ("Hot")
    elif 60<= temperature <= 80:
        return("Warm")
    else: 
        return("Cold")
print("The temperature is" ,check_temp_range(60))
print("The temperature is", check_temp_range(95))
print("The temperature is", check_temp_range(45))
// Homework Hack 1 Javascript: Voting Check
function checkVotingEligibility(age){
    if (age >= 18) {
        return "You can vote!";
    }
    else {
        let yearsLeft = 18 - age;
        return "You are not old enough to vote." + " You have " + yearsLeft + " more years until you are eligible to vote.";
    } 

}

console.log(checkVotingEligibility(5));
console.log(checkVotingEligibility(21));
// Homework Hack 2 Javascript:  Grade Calculator
function calculateGrade(score){
    if (score >= 90) {
        return "A";
    }
    else if (score >= 80) {
        return "B";
    }
    else if (score >= 70) {
        return "C";
    }
    else if (score >= 60) {
        return "D";
    }
    else {
        return "F";
    }
}

console.log(calculateGrade(95));
console.log(calculateGrade(25));
console.log(calculateGrade(72));


// Homework Hack 3 Javascript: Temperature Converter
function convertTemperature(value, scale) {
    if (scale === "C") {
        return (value * 9/5 + 32) + "°F";
    } else if (scale === "F") {
        return ((value - 32) * 5/9) + "°C";
    } else if (scale === "K") {
        return (value - 273) + "°C";
    } else if (scale === "C-K") {
        return (value + 273) + "K";
    } else if (scale === "F-K") {
        return ((value - 32) * 5/9 + 273) + "K";
    } else if (scale === "K-F") {
        return ((value - 273.15) * 9/5 + 32) + "°F";
    } else {
        return "Erorr, Invalid scale";
    }
}

console.log(convertTemperature(100, "C"));
console.log(convertTemperature(212, "F"));
console.log(convertTemperature(0, "K"));
console.log(convertTemperature(100, "C-K"));
console.log(convertTemperature(212, "F-K"));
console.log(convertTemperature(0, "K-F"));
console.log(convertTemperature(100, "A"));