Homework and Popcorn Hacks for 3.7
Homeworks and Popcorn Hacks
3.7.1 Popcorn Hack
age = int(input("How old are you? "))
likes_sweets = input("Are you a fan of sweets? (yes/no): ").lower()
if age >= 10:
print("Enjoy some candy!" if likes_sweets == "yes" else "How about a healthy snack instead?")
else:
print("You can have a yummy fruit snack!")
Enjoy some candy!
3.7.2 Popcorn Hack
savings = 500
dell_price = 800
hp_price = 700
macbook_price = 1200
if savings >= macbook_price:
print("Congratulations! You can afford a MacBook!")
elif savings >= dell_price:
print("Great choice! You can get a Dell laptop!")
elif savings >= hp_price:
print("Awesome! You can buy an HP laptop!")
else:
print("Unfortunately, you need more money to buy a laptop.")
Unfortunately, you need more money to buy a laptop.
3.7.3 Popcorn Hack
%%javascript
let isStoreOpen = true;
let areVegetablesInStock = false;
if (isStoreOpen) {
console.log("The grocery store is open for shopping.");
if (areVegetablesInStock) {
console.log("Grab some fresh veggies!");
} else {
console.log("Consider checking other products on your list.");
}
} else {
console.log("The store is currently closed. Come back later.");
}
<IPython.core.display.Javascript object>
Homework Hack 3.7.1
%%javascript
let age = parseInt(prompt("Enter your age:"));
let hasBall = prompt("Do you have a ball? (yes/no):").toLowerCase();
if (age >= 5 && hasBall === "yes") {
let group = age < 8 ? "under 8" : "8 and older";
console.log(`You can join the game! Your group is: ${group}`);
} else {
console.log("Sorry, you cannot join the game.");
}
<IPython.core.display.Javascript object>