counter = 5
while counter > 0:
print("Hello")
counter -= 1
Hello
Hello
Hello
Hello
Hello
Popcorn Hack #2
- complicated
- (rowan x1, grace x2, sutherland x3) x 4
## defining my variables
outer_counter = 0
inner_counter = 0
last_counter = 0
## establish the loop
while outer_counter <= 4:
print("Rowan")
inner_counter = 0
while inner_counter < 2:
print(" Grace")
last_counter = 0
while last_counter < 3:
print(" Sutherland")
last_counter += 1
inner_counter += 1
outer_counter += 1
Rowan
Grace
Sutherland
Sutherland
Sutherland
Grace
Sutherland
Sutherland
Sutherland
Rowan
Grace
Sutherland
Sutherland
Sutherland
Grace
Sutherland
Sutherland
Sutherland
Rowan
Grace
Sutherland
Sutherland
Sutherland
Grace
Sutherland
Sutherland
Sutherland
Rowan
Grace
Sutherland
Sutherland
Sutherland
Grace
Sutherland
Sutherland
Sutherland
Rowan
Grace
Sutherland
Sutherland
Sutherland
Grace
Sutherland
Sutherland
Sutherland
popcorn hack #3
name = "rowan"
for letter in name:
print(letter)
r
o
w
a
n
%%js
for (let letter of "rowan") {
console.log(letter);
}
<IPython.core.display.Javascript object></IPython.core.display.Javascript>
<IPython.core.display.Javascript object>
popcorn hack #4
# Define a dictionary with people's favorite foods
favorite_foods = {
"Rowan": "Pizza",
"Peyton": "Sushi",
"Carson": "Tacos"
}
# Iterate over the dictionary items
for name, food in favorite_foods.items():
# Print a formatted message for each key-value pair
print(f"{name}'s favorite food is {food} because it's delicious!")
Rowan's favorite food is Pizza because it's delicious!
Peyton's favorite food is Sushi because it's delicious!
Carson's favorite food is Tacos because it's delicious!
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
Cell In[29], line 2
1 # Ask for the user's name
----> 2 name = input("Enter your name: ")
4 # Iterate through each character in the name and print it
5 for letter in name:
File ~/nighthawk/rowan_2025/venv/lib/python3.12/site-packages/ipykernel/kernelbase.py:1282, in Kernel.raw_input(self, prompt)
1280 msg = "raw_input was called, but this frontend does not support input requests."
1281 raise StdinNotImplementedError(msg)
-> 1282 return self._input_request(
1283 str(prompt),
1284 self._parent_ident["shell"],
1285 self.get_parent("shell"),
1286 password=False,
1287 )
File ~/nighthawk/rowan_2025/venv/lib/python3.12/site-packages/ipykernel/kernelbase.py:1325, in Kernel._input_request(self, prompt, ident, parent, password)
1322 except KeyboardInterrupt:
1323 # re-raise KeyboardInterrupt, to truncate traceback
1324 msg = "Interrupted by user"
-> 1325 raise KeyboardInterrupt(msg) from None
1326 except Exception:
1327 self.log.warning("Invalid Message:", exc_info=True)
KeyboardInterrupt: Interrupted by user
%%js
// Define an object to store people's favorite foods
const favoriteFoods = {
"Rowan": "Pizza",
"Peyton": "Sushi",
"Carson": "Tacos"
};
// Use a for...of loop with Object.entries() to iterate over the object
for (const [name, food] of Object.entries(favoriteFoods)) {
// Print a formatted message for each key-value pair
console.log(`${name}'s favorite food is ${food} because it's delicious!`);
}
<IPython.core.display.Javascript object>
HW Hack #1
# While loop to check for correct password
correct_password = "letmein"
while True:
password = input("Enter your password: ")
# Check if the entered password is correct
if password == correct_password:
print("Password is correct.")
break # Exit the loop if the password is correct
else:
print("Incorrect password, please try again.")
Password is correct.
HW Hack #2
# Ask for the user's name
name = input("Enter your name: ")
# Iterate through each character in the name and print it
for letter in name:
print(letter)
r
o
w
a
n
HW Hack #3
# List of fruits
fruits = ["Apple", "Banana", "Mango", "Orange", "Grapes", "Strawberry", "Pineapple"]
# Iterate through the list of fruits and print each one
for fruit in fruits:
print(fruit)
Apple
Banana
Mango
Orange
Grapes
Strawberry
Pineapple