Skip to the content.

3.8 HW

3.8 HW and Popcorn Hacks

Tri 1 Documentation

#creating a count variable
count = 0

#while loop that will print hello 5 times
while count < 5:
    print("hello")
    count += 1
hello
hello
hello
hello
hello
# Create variable for the outer counter so the whole process can be repeated 4 times
outer_counter = 0

while outer_counter < 4:
    print("Syed")
    
# Create a variable for the inner counter so the process can be repeated 2 times
    inner_counter = 0
    while inner_counter < 2:
        print(" Rayhaan")
        inner_counter += 1
    
    inner_counter = 0
    while inner_counter < 3:
        print("Sheeraj")
        inner_counter += 1
    
    outer_counter += 1
Syed
 Rayhaan
 Rayhaan
Sheeraj
Sheeraj
Sheeraj
Syed
 Rayhaan
 Rayhaan
Sheeraj
Sheeraj
Sheeraj
Syed
 Rayhaan
 Rayhaan
Sheeraj
Sheeraj
Sheeraj
Syed
 Rayhaan
 Rayhaan
Sheeraj
Sheeraj
Sheeraj
# Create a variable for the name that will be printed
name = "Rayhaan"

# for loop that will print each letter in the name
for letter in name:
    print(letter)
R
a
y
h
a
a
n
# Create a dictionary

my_info = {
    "name": "Rayhaan",
    "age": 16,
    "city": "San Diego"
}

# Iterate through the dictionary and print the values in the dictionary
for name, age in my_info.items():
    print(f"{name} is {age}")
name is Rayhaan
age is 16
city is San Diego
# Homework Hack #1 

# Create the password
correct_password = "python123"

# Use variable to store the user's input
user_password = ""

# Use a while loop to keep checking for the password until the password is correct
while user_password != correct_password:
    user_password = input("Enter the password: ")
    if user_password == correct_password:
        print("The password is correct.")
    else:
        print("The password is incorrect. Please try again.")
The password is correct.
# Homework Hack #2

# Ask for an input from the user
username = input("Enter your name: ")

# Use a for loop to print each letter in the username
for letter in username:
    print(letter)


R
a
y
h
a
a
n
# Homework Hack #3

# Create a list of fruits
fruits = ["apple", "banana", "cherry", "grape", "pineapple", "orange", "watermelon", "mango" ]

for fruit in fruits:
    print(fruit)
apple
banana
cherry
grape
pineapple
orange
watermelon
mango