Popcorn hacks
#Popcorn hack 1
user_age = int(input("Enter your age: "))
enjoys_candies = input("Do you enjoy candies? (yes/no): ").lower()
if user_age >= 10:
if enjoys_candies == "yes":
print("You can have some chocolate!")
else:
print("You can have a nutritious snack.")
else:
print("You get a healthy fruit snack.")
%%js
// Popcorn hack 1
let userAge = parseInt(prompt("Enter your age: "));
let enjoysCandies = prompt("Do you enjoy candies? (yes/no): ").toLowerCase();
if (userAge >= 10) {
if (enjoysCandies === "yes") {
console.log("You can have some chocolate!");
} else {
console.log("You can have a nutritious snack.");
}
} else {
console.log("You get a healthy fruit snack.");
}
%%js
// Popcorn hack 2
// Budget
let budget = 500;
// Computer prices
let dellCost = 800;
let hpCost = 700;
let macbookCost = 1200;
// Determine which computer you can buy
if (budget >= macbookCost) {
console.log("You can buy a MacBook!");
} else if (budget >= dellCost) {
console.log("You can buy a Dell laptop!");
} else if (budget >= hpCost) {
console.log("You can buy an HP laptop!");
} else {
console.log("You don't have enough money to buy a laptop.");
}
#Popcorn hack 2
# Budget
budget = 500
# Computer prices
dell_cost = 800
hp_cost = 700
macbook_cost = 1200
# Determine which computer you can buy
if budget >= macbook_cost:
print("You can buy a MacBook!")
elif budget >= dell_cost:
print("You can buy a Dell laptop!")
elif budget >= hp_cost:
print("You can buy an HP laptop!")
else:
print("You don't have enough money to buy a laptop.")
#Popcorn hack 3
# Grocery Conditions
store_open = True # Changed variable name
vegetables_available = False # Changed variable name
# Shopping logic based on store and item availability
if store_open:
print("You can go grocery shopping.")
if vegetables_available:
print("Buy some fresh vegetables.")
else:
print("Check for other items on your list.")
else:
print("The store is closed, shop another day.")
%%js
// Popcorn hack 3
// Grocery Conditions
let storeOpen = true; // Changed variable name
let vegetablesAvailable = false; // Changed variable name
// Shopping logic based on store and item availability
if (storeOpen) {
console.log("You can go grocery shopping.");
if (vegetablesAvailable) {
console.log("Buy some fresh vegetables.");
} else {
console.log("Check for other items on your list.");
}
} else {
console.log("The store is closed, shop another day.");
}
Homework Hack
%%js
// Homework hack 1
// Function to check eligibility for the game
function checkEligibility() {
// Get user age
let age = parseInt(prompt("Enter your age: "));
// Check if the input is a valid number
if (isNaN(age)) {
console.log("Please enter a valid number for age.");
return;
}
// Check ball ownership
let hasBall = prompt("Do you have a ball? (yes/no): ").toLowerCase();
// Check eligibility
if (age >= 5 && hasBall === "yes") {
let group = age < 8 ? "Group A (under 8)" : "Group B (8 and older)";
console.log(`You can join the game! You are in ${group}.`);
} else {
console.log("You cannot join the game.");
}
}
// Call the function to execute the program
checkEligibility();
#Homework hack 1
# Function to check eligibility for the game
def check_eligibility():
# Get user age
age = input("Enter your age: ")
# Check if the input is a valid number
if not age.isdigit():
print("Please enter a valid number for age.")
return
age = int(age)
# Check ball ownership
has_ball = input("Do you have a ball? (yes/no): ").lower()
# Check eligibility
if age >= 5 and has_ball == "yes":
group = "Group A (under 8)" if age < 8 else "Group B (8 and older)"
print(f"You can join the game! You are in {group}.")
else:
print("You cannot join the game.")
# Call the function to execute the program
check_eligibility()