Skip to the content.
Home Accounts Setup Verify Play Hacks

Gaheera Babbar P4 Popcorn Hacks 3.7

3.7 Lesson Popcorn and Homework Hacks

Python

#Python Popcorn Hack 1: Try adding an additional condition for hiking
#I added the conditions checking for water and sunscreen
weather = "sunny"
transportation = "available"
boots = "not present"
water = "brought" #New Variable
sunscreen = "applied" #New Variable

print("The weather is " + weather)
print("Your transportation is " + transportation)
print("Your boots are " + boots)
print("Your water is " + water)
print("Your sunscreen is " + sunscreen) 

if weather == "sunny":
    if transportation == "available":
        if boots == "present":
            if water == "brought" and sunscreen == "applied": #New Conditionals, checks for water and sunscreen
                print("You are fully ready to go hiking!")
            else:
                print("Make sure to bring water and apply sunscreen.")
        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 not present
You need to find your boots first.
#Python Bonus Popcorn Hack: Movie Night
#I changed the boolean values for the projector and snacks, resulting in the print "You need to get more snacks" instead.
living_room_available = True
projector_working = True #Changed boolean value from false to true
enough_snacks = False #Changed boolean value from true to false

if living_room_available:
    if projector_working:
        if enough_snacks:
            print("You're ready to host the movie night!")
        else:
            print("You need to get more snacks. Ideas: Popcorn, Candy, Soda")
    else:
        print("You need to fix or replace the projector.")
else:
    print("The living room is not available for the movie night. Find another room!")
You need to get more snacks. Ideas: Popcorn, Candy, Soda
#Python Homework 1: Write Python pseudocode to decide whether or not to go to the beach.
# Define the variables for weather, sunscreen, and snacks
weather = "sunny"  # Can be "sunny" or something else
sunscreen = "have"  # Can be "have" or "not have"
snacks = "enough"  # Can be "enough" or "not enough"

# Check the conditions
if weather == "sunny":  # Check if the weather is sunny
    if sunscreen == "have":  # Check if you have sunscreen
        if snacks == "enough":  # Check if you have enough snacks
            print("You are ready for the beach!")  # All conditions met
        else:
            print("You need to get more snacks first.")  # Missing snacks
    else:
        print("You need to buy sunscreen.")  # Missing sunscreen
else:
    print("It's not a good day for the beach.")  # Weather is not sunny


You are ready for the beach!
#Python Homework 2: Write a Python code that checks if you can adopt a pet.

at_least_18_yrs_old = True
at_least_50_sqr_ft = True
possible_pet_care = True
#Check Conditions
if at_least_18_yrs_old:
    if at_least_50_sqr_ft:
        if possible_pet_care:
             print("You can adopt a pet!") #all conditions met
        else:
            print("You must be able to make time for the pet.") #cannot care for pet
    else:
        print("You must have a bigger home.") #not enough space
else:
    print("You must be 18 to adopt a pet") #not old enough

You can adopt a pet!
#Python Homework 3: Write Python code to determine whether or not to participate in a marathon.
weather_clear = True
have_running_shoes = True
ten_days_of_practice = True
if weather_clear:
    if have_running_shoes:
        if ten_days_of_practice:
            print("You are ready for the marathon.")
        else:
            print("You need to practice more.")
    else:
        ("You need to buy running shoes")
else: 
    ("It is not the right time for a marathon")
    
You are ready for the marathon.
%%js
// JS Popcorn Hack 1: Try adding an additional condition for hiking
//I added the conditions checking for water and sunscreen
let weather = "sunny";
let transportation = "available";
let boots = "not present";
let water = "brought"; //water conditional added
let sunscreen = "applied"; //sunscreen conditional added

console.log("The weather is " + weather);
console.log("Your transportation is " + transportation);
console.log("Your boots are " + boots);
console.log("Your water is " + water);
console.log("Your sunscreen is " + sunscreen);

if (weather === "sunny") {
    if (transportation === "available") {
        if (boots === "present") {
            if (water === "brought" && sunscreen === "applied") {
                console.log("You are fully ready to go hiking!");
            } else {
                console.log("Make sure to bring water and apply sunscreen.");
            }
        } 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.");
}


%%js
// JS Popcorn Hack 2: Changing Booleans
// I changed the projetor boolean value and snack boolean value, changing the output print to "You need to get more snacks."
let living_room_available = true;
let projector_working = true; //changed boolean value from false to true
let enough_snacks = false; //changed boolean value from true to false

if (living_room_available) {
    if (projector_working) {
        if (enough_snacks) {
            console.log("You're ready to host the movie night!");
        } else {
            console.log("You need to get more snacks. Ideas: Popcorn, Candy, Soda");
        }
    } else {
        console.log("You need to fix or replace the projector.");
    }
} else {
    console.log("The living room is not available for the movie night. Find another room!");
}

%%js
// JS Homework Hack 1: Write Javascript pseudocode to decide whether or not to study for an exam.
// Define the variables for study materials, quiet place, and tiredness
let hasMaterials = true;
let quietPlace = true;  
let isTired = false; 

// Check the conditions
if (hasMaterials) {  // Check if you have your study materials
    if (quietPlace) {  // Check if you have a quiet place to study
        if (!isTired) {  // Check if you are not feeling too tired
            console.log("You are ready to study!");  // All conditions met
        } else {
            console.log("You should take a nap or rest before studying.");  // Too tired
        }
    } else {
        console.log("You need to find a quiet place to study.");  // No quiet place
    }
} else {
    console.log("You need to gather your study materials first.");  // Missing materials
}


<IPython.core.display.Javascript object>
%%js
// JS Homework Hack 2: Write Javascript code deciding whether or not you can bake a cake.
// Define the variables for ingredients, oven status, and time
let hasFlour = true;  // true if you have flour
let hasEggs = true;   // true if you have eggs
let hasSugar = false; // true if you have sugar
let ovenWorking = true;  // true if the oven is working
let timeAvailable = 2.5; // Time available in hours

// Check if you have all ingredients
if (hasFlour && hasEggs && hasSugar) {
    // Check if the oven is working
    if (ovenWorking) {
        // Check if you have at least 2 hours
        if (timeAvailable >= 2) {
            console.log("You can start baking the cake!");  // All conditions met
        } else {
            console.log("You need to find more time to bake and cool the cake.");  // Not enough time
        }
    } else {
        console.log("You need to fix or replace the oven.");  // Oven not working
    }
} else {
    // Determine what ingredients are missing
    let missingIngredients = [];
    if (!hasFlour) missingIngredients.push("flour");
    if (!hasEggs) missingIngredients.push("eggs");
    if (!hasSugar) missingIngredients.push("sugar");
    
    console.log("You are missing the following ingredients: " + missingIngredients.join(", "));  // Missing ingredients
}




<IPython.core.display.Javascript object>
%%js
// JS Homework Hack 3: Write Javascript code to decide whether or not you can go camping.
// Define the variables for weather, tent, and food/water
let weather = "clear";  // Can be "clear" or something else
let hasTent = true;     // true if you have a tent
let enoughFoodAndWater = false;  // true if you have enough food and water for the trip

// Check the conditions
if (weather === "clear") {  // Check if the weather is clear
    if (hasTent) {  // Check if you have a tent
        if (enoughFoodAndWater) {  // Check if you have enough food and water
            console.log("You are ready to go camping!");  // All conditions met
        } else {
            console.log("You need to pack more food and water.");  // Missing food or water
        }
    } else {
        console.log("You need to buy or borrow a tent.");  // No tent
    }
} else {
    console.log("It's not a good time for camping due to the weather.");  // Bad weather
}

<IPython.core.display.Javascript object>