Big Idea 3 Section 6
Popcorn hacks and Homework for Section 6 of Big Idea 3
Big Idea 3 Section 6
Popcorn Hack #1
bank_balance = 34
# Conditional statement
item_price = 20
if bank_balance >= item_price:
print("You can buy the item!")
else:
print("You cannot buy the item.")
You can buy the item!
%%js
let bank_balance = 34;
// Conditional statement
let item_price = 20;
if (bank_balance >= item_price) {
console.log("You can buy the item!");
} else {
console.log("You cannot buy the item.");
}
<IPython.core.display.Javascript object>
Popcorn Hack #2
sunny = True
if sunny:
print("It is sunny outside!")
else:
print("It's cloudy outside :(")
It is sunny outside!
%%js
let sunny = true;
if (sunny) {
console.log("It is sunny outside!");
} else {
console.log("It's cloudy outside :(");
}
<IPython.core.display.Javascript object>
Popcorn Hack #3
%%js
let will_i_be_lucky_today = Math.floor(Math.random() * 6) + 1;
console.log("Checking for luckiness today");
console.log(`You got a luck score of ${will_i_be_lucky_today}`);
if (will_i_be_lucky_today === 1) {
console.log("Oh no! You got a one. You will be unlucky today!");
} else if (will_i_be_lucky_today <= 3) {
console.log("You got a low number. Nothing will happen!");
} else if (will_i_be_lucky_today === 4) {
console.log("Not bad! You will be somewhat lucky today.");
} else if (will_i_be_lucky_today === 5) {
console.log("Great score! You got a five, you will be lucky.");
} else {
console.log("Awesome! You got a six! You're going to be very lucky today!");
}
<IPython.core.display.Javascript object>
Homework 1
def random_question(question, correct_answer):
answer = input(question + " ")
if answer.lower() == correct_answer.lower():
print("correct!")
return 1
else:
print(f"wrong! the correct answer was: {correct_answer}")
return 0
def play_quiz():
score = 0
score += random_question("What is the capital of France?", "Paris")
score += random_question("What is the largest planet in our solar system?", "Jupiter")
score += random_question("What is the chemical symbol for water?", "H2O")
score += random_question("Who wrote 'Animal Farm'?", "George Orwell")
score += random_question("How many continents are there?", "7")
print(f"Your final score is: {score}/5")
play_quiz()
wrong! the correct answer was: Paris
correct!
wrong! the correct answer was: H2O
correct!
correct!
Your final score is: 3/5