3.6 Popcorn Hacks
3.6 Conditionals
Popcorn Hack 1 in Python
score = 95
# Conditional statement
if score >= 90:
print("You got an A on the test!")
else:
print("You didn't get an A on the test.")
You got an A on the test!
Popcorn Hack 1 in Javascript
%%js
let score = 95;
// Conditional statement
if (score >= 90) {
console.log("You got an A on test!");
} else {
console.log("You didn't get an A on the test.");
}
<IPython.core.display.Javascript object>
Popcorn Hack 2 in python
commited_crime = True
if commited_crime:
print("Go To Jail")
else:
print("You are innocent")
Go To Jail
Popcorn Hack 3 in Javascript
%%js
let roll_dice = Math.floor(Math.random() * 6) + 1;
console.log("Rolling the dice...");
console.log(`You rolled a ${roll_dice}`);
if (roll_dice === 1) {
console.log("Oh no! You rolled a 1. Try again!");
} else if (roll_dice === 2) {
console.log("oh, thats bad, you rolled a 2");
} else if (roll_dice == 3) {
console.log("Uh oh, you rolled a 3!");
} else if (roll_dice === 4) {
console.log("Not bad! You rolled a 4.");
} else if (roll_dice === 5) {
console.log("Great roll! You rolled a 5.");
} else {
console.log("Awesome! You rolled a 6! You're on a roll!");
}
<IPython.core.display.Javascript object>