weather = "sunny"
transportation = "available"
boots = "present"
location_determined = True
print("The weather is " + weather)
print("Your transportation is " + transportation)
print("Your boots are " + boots)
if weather == "sunny":
if transportation == "available":
if boots == "present":
if location_determined:
print("You are ready to go hiking!")
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.")
The weather is sunny
Your transportation is available
Your boots are present
You are ready to go hiking!
3.7.2 Popcorn Hack
%%javascript
let weather = "sunny";
let transportation = "available";
let boots = "not present";
let location_determined = true;
console.log("The weather is " + weather);
console.log("Your transportation is " + transportation);
console.log("Your boots are " + boots);
if (weather === "sunny") {
if (transportation === "available") {
if (boots === "present") {
if (location_determined) {
console.log("You are ready to go hiking!");
} 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.");
}
<IPython.core.display.Javascript object>
3.7.3 Homework
Hack 1:
# Pseudocode to decide if you should go to the beach
# Check the conditions
IF weather == "sunny":
# Check if you have sunscreen
IF have_sunscreen == True:
# Check if you have enough snacks
IF have_enough_snacks == True:
PRINT "You are ready for the beach!"
# If you don't have enough snacks
ELSE:
PRINT "You need to get more snacks before going to the beach."
# If you don't have sunscreen
ELSE:
PRINT "You need to buy sunscreen before going to the beach."
# If the weather is not sunny
ELSE:
PRINT "It's not a good day for the beach."
The weather is sunny
Your sunscreen is packed
Your snacks are enough
You are ready for the beach!
Hack 2:
def check_adoption_eligibility(age, space, availability):
if age >= 18:
if space > 50:
if availability:
return "You can adopt the pet!"
else:
return "You need to make time to take care of the pet."
else:
return "You need a bigger home."
else:
return "You must be at least 18 to adopt a pet."
print(check_adoption_eligibility(17, 60, True))
print(check_adoption_eligibility(20, 45, True))
Hack 3:
def check_marathon_readiness(weather, shoes, practice_days):
if weather == "clear"
if shoes == "present":
if practice_days >= 10:
print("You are ready for the marathon!")
else:
print("You need to practice more.")
else:
print("You need to buy shoes first.")
else:
print("It's not the right time for the marathon.")
check_marathon_readiness("clear", "present", 12)
check_marathon_readiness("clear", "absent", 12)
3.7.4
Hack 1:
// Pseudocode to decide if you should study for an exam
// Check the conditions
IF have_study_materials == true:
// Check if you have a quiet place to study
IF have_quiet_place == true:
// Check if you're feeling too tired
IF feeling_tired == false:
PRINT "You are ready to study!"
// If you're too tired
ELSE:
PRINT "You should take a nap or rest before studying."
// If you don't have a quiet place to study
ELSE:
PRINT "You need to find a quiet location before studying."
// If you don't have your study materials
ELSE:
PRINT "You need to gather your study materials first."
Hack 2:
%%js
function startBaking(allIngredients, ovenWorking, bakeCoolTime) {
if (allIngredients) {
if (ovenWorking) {
if (bakeCoolTime >= 2) {
console.log("You can start baking!");
} else {
console.log("You need to find more time.");
}
} else {
console.log("You need to fix or replace the oven.");
}
} else {
console.log("You need to gather all the ingredients.");
}
}
startBaking(true, true, 3);
startBaking(true, false, 1);
Hack 3:
%%javascript
let weather = "clear";
let tent = "packed";
let food_water = "enough";
console.log("The weather is " + weather);
console.log("Your tent is " + tent);
console.log("Your food and water supply is " + food_water);
if (tent === "packed") {
if (food_water === "enough") {
if (weather === "clear") {
console.log("You are ready to go camping!");
} else {
console.log("You need to buy or borrow a tent.");
}
} else {
console.log("You need to pack more.");
}
} else {
console.log("It's not a good time to go camping.");
}