Skip to the content.

3.8teamteach_ipynb_2_

count = 0
while count < 5:
    print("hello")
    count += 1


hello
hello
hello
hello
hello

3.8.2 Popcorn Hack 2:

# Define the names
first_name = "Hannah"
middle_name = "Ren"
last_name = "Li"

# Loop to repeat the entire process 4 times
for _ in range(4):
    print(first_name)         # Print first name 1 time
    for _ in range(2):
        print(middle_name)    # Print middle name 2 times
    for _ in range(3):
        print(last_name)      # Print last name 3 times

Hannah
Ren
Ren
Li
Li
Li
Hannah
Ren
Ren
Li
Li
Li
Hannah
Ren
Ren
Li
Li
Li
Hannah
Ren
Ren
Li
Li
Li

3.8.3 Popcorn Hack 3:

name = "Hannah"

for letter in name:
    print(letter)

H
a
n
n
a
h

3.8.4 Popcorn Hack #4:

# Create a dictionary
person_info = {
    "name": "Hannah Li",
    "age": 17,
    "city": "San Diego",
    "occupation": "Student"
}

# Iterate through each key-value pair in the dictionary
for key, value in person_info.items():
    print(f"Key: {key}, Value: {value} - This is a great detail!")

3.8.5 Hack #1:

# Define the correct password
correct_password = "ilovemymom"

# Loop until the user enters the correct password
while True:
    # Ask the user for the password
    entered_password = input("Please enter your password: ")
    
    # Check if the password is correct
    if entered_password == correct_password:
        print("Password is correct!")
        break  # Exit the loop if the password is correct
    else:
        print("Incorrect password, please try again.")

Incorrect password, please try again.
Incorrect password, please try again.
Incorrect password, please try again.
Password is correct!

3.8.5 Hack #2:

# Ask the user for their name
name = input("Please enter your name: ")

# Iterate through the name letter by letter
for letter in name:
    print(letter)

h
a
n
n
a
h

3.8.5 Hack #3:

# Create a list of fruits
fruits = ["Apple", "Banana", "Orange", "Mango", "Pineapple", "Grapes", "Strawberry"]

# Iterate through the list and print each fruit
for fruit in fruits:
    print(fruit)

Apple
Banana
Orange
Mango
Pineapple
Grapes
Strawberry