Popcorn Hacks for 3.6
age = 16
if age >= 45:
print ("You are old!")
else:
print ("You are young!")
You are young!
%%javascript
let age = 16
if (age >= 45) {
console.log("You are old!");
} else {
console.log("You are young!");
}
<IPython.core.display.Javascript object>
has_a_pet = False
if has_a_pet:
print ("What kind of pet do you have?")
else:
print ("You should get a pet!")
You should get a pet!
%%javascript
let has_a_pet = false;
if (has_a_pet) {
console.log("What kind of pet do you have?");
} else {
console.log("You should get a pet!");
}
<IPython.core.display.Javascript object>
import random
lives_in_game = random.randint(1, 5)
print(f"You earned {lives_in_game}")
if lives_in_game == 1:
print ("You died! Try again!")
elif lives_in_game <=3:
print ("Oh no! Try again")
elif lives_in_game == 4:
print ("Almost there")
else:
print ("Congrats, you won!")
You earned 3
Oh no! Try again
Popcorn Hacks for 3.7
age = int(input("Enter your age: "))
likes_sweets = input("Do you like sweets? (yes/no/maybe): ").lower()
if age >= 40:
if likes_sweets == "yes":
print("You can have candy!")
elif likes_sweets == "maybe":
print ("Have a sweet treat!")
else:
print("You can have a healthy snack.")
else:
print("You get a fruit snack.")
Have a sweet treat!
savings = 900
# Laptop prices
dell_price = 900
chromebook_price = 500
macbook_price = 2500
# Determine which laptop you can buy
if savings >= macbook_price:
print("You can buy a MacBook!")
elif savings >= dell_price:
print("You can buy a Dell laptop!")
elif savings >= chromebook_price:
print("You can buy an chromebook!")
else:
print("You don't have enough money to buy a laptop.")
You can buy a Dell laptop!
%%javascript
// Weather Conditions
let is_sunny_outside = true;
let is_under_80_degrees = false;
// Logic based on weather conditions
if (is_sunny_outside) {
console.log("You can go on a walk outside!");
if (is_under_80_degrees) {
console.log("Go for a run!");
} else {
console.log("Stay inside");
}
} else {
console.log("Bad weather! Stay inside");
}
<IPython.core.display.Javascript object>
Homework for 3.6
import sys
def question_with_response(prompt):
answer = input(prompt)
return answer
questions = 6
correct = 0
user_name = question_with_response("Enter your name: ")
print(f'Hi, {user_name}! You are running Python using {sys.executable}.')
ready = question_with_response("Are you ready to take a music quiz?(yes/no): ")
if ready.lower() != 'yes':
print("Come back when you're ready! Goodbye.")
sys.exit()
q1 = question_with_response("1. Which music artist has the most Grammis? a) Bruno Mars b) Lady Gaga c) Madonna d) Beyonce: ")
if q1.lower() == "d":
print("Correct!")
correct += 1
else:
print("Incorrect. The correct answer is d) Beyonce.")
q2 = question_with_response("2. Which singer has the most monthly listeners on Spotify? a) Ed Sheeran b) Justin Bieber c) Billie Eilish d) The Weeknd: ")
if q2.lower() == "c":
print("Correct!")
correct += 1
else:
print("Incorrect. The correct answer is c) Billie Eilish.")
q3 = question_with_response("3. What music video has the highest view on Youtube? a) Gangnam Style b) Despacito c) Baby Shark d) Uptown Funk:")
if q3.lower() == "c":
print("Correct!")
correct += 1
else:
print("Incorrect. The correct answer is c) Baby Shark.")
q4 = question_with_response("4. Which rapper is with Rihanna? a) A$AP Rocky b) Drake c) Diddy d) Eminem: ")
if q4.lower() == "a":
print("Correct!")
correct += 1
else:
print("Incorrect. The correct answer is a) A$AP Rocky.")
q5 = question_with_response("5. What streaming platform is most popular? a) Apple Music b) Spotify c)Sound cloud: ")
if q5.lower() == "b":
print("Correct!")
correct += 1
else:
print("Incorrect. The correct answer is b) Spotify.")
q6 = question_with_response("6. What is the name of a former British boy band? a) 2 Direction b) 1 Direction c) Right direction d) Left direction : ")
if q6.lower() == "b":
print("Correct!")
correct += 1
else:
print("Incorrect. The correct answer is b) 1 Direction.")
print(f'{user_name}, you scored {correct}/{questions}!')
Hi, prajna! You are running Python using /Users/prajnaraj/nighthawk/prajna_2025/venv/bin/python.
Correct!
Incorrect. The correct answer is c) Billie Eilish.
Correct!
Correct!
Correct!
Correct!
Homework for 3.7
age = int(input("Enter your age: "))
has_license = input("Do you have a drivers license? (yes/no): ").lower()
# Check if the child can join the game
can_drive = age >= 16 and has_license == "yes"
if can_drive:
if age > 16:
print("Wow! You must be great at driving!")
else:
print("Keep practicing!.")
else:
print("Sorry, you can't join the game yet.")
Wow! You must be great at driving!