3.6 and 3.7 Homework and Popcorn hacks
3.6
Popcorn Hacks
Hack #1
# Step 1: Add a variable that represents temperature
temperature = 50 # 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")
elif (temperature >= 60):
print("It's warm")
# Step 3: Otherwise, print it's a cold day
else:
print("It's a cold day")
Hack #2
%%js
let score = 85;
if (score >= 60) {
console.log("You passed!");
}
else if (score < 60) {
console.log("you are a silly goose and did not pass")
}
Python Homework Hacks
Hack 1
def checkVotingEligibility(age):
if (age >= 18): return "You are eligible to vote!"
else: return "You are not eligible to vote yet."
print(checkVotingEligibility(12))
print(checkVotingEligibility(18))
print(checkVotingEligibility(20))
Hack #2
def getGrade(score):
if (score >= 90): return "A"
elif (score >= 80): return "B"
elif (score >= 70): return "C"
elif (score >= 60): return "D"
else: return "F"
print(getGrade(62))
print(getGrade(83))
print(getGrade(99))
print(getGrade(71))
print(getGrade(32))
Hack #3
def convertTemperature(value, scale):
if (scale == "C"):
result = (value * (9/5)) + 32
print (result, "°F")
else:
result = (value - 32) * (5/9)
print (result, "°C")
convertTemperature(233, "C")
convertTemperature(38, "F")
JS 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(12));
console.log(checkVotingEligibility(18));
console.log(checkVotingEligibility(20));
Hack #2
%%js
function getGrade(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(getGrade(62));
console.log(getGrade(83));
console.log(getGrade(99));
console.log(getGrade(71));
console.log(getGrade(32));
Hack #3
%%js
function convertTemperature(value, scale) {
let result;
if (scale === "C") {
result = (value * (9/5)) + 32;
console.log(result + " °F");
} else {
result = (value - 32) * (5/9);
console.log(result + " °C");
}
}
convertTemperature(233, "C");
convertTemperature(38, "F");
3.7
Popcorn Hacks
Hack #1
weather = "sunny"
transportation = "available"
boots = "not present"
lazy = False
print("The weather is " + weather)
print("Your transportation is " + transportation)
print("Your boots are " + boots)
print("you laziness is " + lazy)
if weather == "sunny":
if transportation == "available":
if boots == "present":
if (not lazy):
print("You are ready to go hiking!")
else:
print("you need to get some energy first.")
else:
print("You need to find your boots first.")
else:
print("You need to arrange transportation.")
else:
print("It's not good weather for hiking.")
# added laziness condition
Hack #2
%%js
let weather = "sunny";
let transportation = "available";
let boots = "not present";
let lazy = true;
console.log("The weather is " + weather);
console.log("Your transportation is " + transportation);
console.log("Your boots are " + boots);
console.log("you laziness is " + lazy)
if (weather === "sunny") {
if (transportation === "available") {
if (boots === "present") {
if (!lazy) {
console.log("You are ready to go hiking!");
}
else {
console.log("You need to grab youself some energy first, maybe go eat some ice cream")
}
}
else {
console.log("You need to find your boots first.");
}
}
else {
console.log("You need to arrange transportation.");
}
}
else {
console.log("It's not good weather for hiking.");
}
Python Homework Hacks
Hack 1
"""
BEGIN<br>
IF weather == "sunny" THEN<br>
IF have_sunscreen == TRUE THEN<br>
IF have_enough_snacks == TRUE THEN<br>
PRINT "You are ready for the beach!"<br>
ELSE<br>
PRINT "You need to get more snacks first."<br>
ENDIF<br>
ELSE<br>
PRINT "You should buy sunscreen first."<br>
ENDIF<br>
ELSE<br>
PRINT "It's not a good day for the beach."<br>
ENDIF<br>
END<br>
"""
you should get some snacks
Hack #2
age = 21
space = 62
availability = True
if age >= 18:
if space >= 50:
if availability: print("You can adopt a pet!")
else: print ("you need to make time")
else: print ("you need a bigger home")
else: print ("you need to be older")
You can adopt a pet!
Hack #3
weather = "clear"
shoes = False
practiceDays = 12
if weather == "clear":
if shoes:
if practiceDays >= 10: print("You can run a marathon!")
else: print ("you need to train for more time")
else: print ("you need some good shoes")
else: print ("it's not a good day to run a marathon")
JS Homework Hacks
Hack 1
"""
BEGIN<br>
IF have_study_materials == TRUE THEN<br>
IF have_quiet_place == TRUE THEN<br>
IF feeling_tired == FALSE THEN<br>
PRINT "You are ready to study!"<br>
ELSE<br>
PRINT "You should take a nap or rest first."<br>
ENDIF<br>
ELSE<br>
PRINT "You need to find a quiet place to study."<br>
ENDIF<br>
ELSE<br>
PRINT "You need to gather your study materials first."<br>
ENDIF<br>
END<br>
"""
Hack #2
%%js
// Variables representing the conditions
let haveFlour = true; // Change to false if you don't have flour
let haveEggs = true; // Change to false if you don't have eggs
let haveSugar = true; // Change to false if you don't have sugar
let ovenWorking = true; // Change to false if the oven is not working
let timeAvailable = 3; // Change to reflect the number of hours you have
// Function to check if you can bake the cake
function canBakeCake() {
if (haveFlour && haveEggs && haveSugar) {
if (ovenWorking) {
if (timeAvailable >= 2) {
console.log("You can start baking!");
} else {
console.log("You need to find more time to bake and cool the cake.");
}
} else {
console.log("You need to fix or replace the oven.");
}
} else {
let missingIngredients = [];
if (!haveFlour) missingIngredients.push("flour");
if (!haveEggs) missingIngredients.push("eggs");
if (!haveSugar) missingIngredients.push("sugar");
console.log("You are missing the following ingredients: " + missingIngredients.join(", ") + ".");
}
}
// Call the function to check if you can bake the cake
canBakeCake();
Hack #3
%%js
// Variables representing the conditions
let weatherClear = true; // Change to false if the weather is not clear
let haveTent = true; // Change to false if you don't have a tent
let haveEnoughFoodAndWater = true; // Change to false if you don't have enough food and water
// Function to check if you can go camping
function canGoCamping() {
if (weatherClear) {
if (haveTent) {
if (haveEnoughFoodAndWater) {
console.log("You are ready to go camping!");
} else {
console.log("You need to pack more food and water for the trip.");
}
} else {
console.log("You need to buy or borrow a tent.");
}
} else {
console.log("It's not a good time for camping due to the weather.");
}
}
// Call the function to check if you can go camping
canGoCamping();