Popcorn hacks
#Popcorn hack 1
# Get the current temperature from the user
temperature = int(input("Enter the current temperature in degrees Celsius: "))
# Conditional statement to provide advice based on temperature
if temperature > 20:
print("It's warm outside! You can wear a t-shirt.")
else:
print("It's a bit chilly. You should wear a jacket.")
%% js
// Popcorn hack 1
// Get the current temperature from the user
let temperature = prompt("Enter the current temperature in degrees Celsius:");
// Conditional statement to provide advice based on temperature
if (temperature > 20) {
console.log("It's warm outside! You can wear a t-shirt.");
} else {
console.log("It's a bit chilly. You should wear a jacket.");
}
%%js
// Popcorn hack 2
// Get user input to set the boolean value
let userInput = prompt("Do you want to proceed? (yes/no):").toLowerCase();
// Convert the input to a boolean value
let isProceed = (userInput === 'yes');
// Conditional check using the boolean variable
if (isProceed) {
console.log("You chose to proceed.");
} else {
console.log("You chose not to proceed.");
}
#Popcorn hack 2
# Get user input to set the boolean value
user_input = input("Do you want to proceed? (yes/no): ").lower()
# Convert the input to a boolean value
is_proceed = user_input == 'yes'
# Conditional check using the boolean variable
if is_proceed:
print("You chose to proceed.")
else:
print("You chose not to proceed.")
#Popcorn hack 3
import random
# Generate a random number between 1 and 100
random_number = random.randint(1, 100)
# Conditional check
if random_number > 50:
print(f"The random number is {random_number}. It's greater than 50!")
else:
print(f"The random number is {random_number}. It's 50 or less.")
%%js
//Popcorn hack 3
// Generate a random number between 1 and 100
let randomNumber = Math.floor(Math.random() * 100) + 1;
// Conditional check
if (randomNumber > 50) {
console.log(`The random number is ${randomNumber}. It's greater than 50!`);
} else {
console.log(`The random number is ${randomNumber}. It's 50 or less.`);
}
Homework Hack
import random
# Questions and answers
quiz_questions = [
{
"question": "What is the capital of France?",
"options": ["A) Paris", "B) Rome", "C) Berlin", "D) Madrid"],
"answer": "A"
},
{
"question": "What is the largest planet in our solar system?",
"options": ["A) Earth", "B) Jupiter", "C) Saturn", "D) Mars"],
"answer": "B"
},
{
"question": "What is the chemical symbol for gold?",
"options": ["A) Au", "B) Ag", "C) Pb", "D) Fe"],
"answer": "A"
},
{
"question": "Which language is primarily spoken in Brazil?",
"options": ["A) Spanish", "B) Portuguese", "C) English", "D) French"],
"answer": "B"
},
{
"question": "What is the smallest prime number?",
"options": ["A) 1", "B) 2", "C) 3", "D) 4"],
"answer": "B"
}
]
def ask_question(question_data):
"""Function to ask a question and check the answer."""
print(question_data["question"])
for option in question_data["options"]:
print(option)
answer = input("Your answer (A/B/C/D): ").upper()
if answer == question_data["answer"]:
print("Correct!\n")
else:
print(f"Wrong! The correct answer was {question_data['answer']}.\n")
def run_quiz(questions):
"""Function to run the quiz."""
print("Welcome to the Quiz Game!\n")
random.shuffle(questions) # Shuffle the questions for randomness
for question in questions:
ask_question(question)
print("Quiz finished! Thanks for playing!")
# Run the quiz
run_quiz(quiz_questions)