3.8 Hacks
Python/Javascript Popcorn and HW hacks
count = 0
while count < 5:
print("hello")
count += 1
repeat_count = 0
while repeat_count < 4:
# Print first name one time
print("Vibha")
# Print middle name two times
middle_count = 0
while middle_count < 2:
print("Jayanth")
middle_count += 1
# Print last name three times
last_count = 0
while last_count < 3:
print("Mandayam")
last_count += 1
# Increment repeat count
repeat_count += 1
Vibha
Jayanth
Jayanth
Mandayam
Mandayam
Mandayam
Vibha
Jayanth
Jayanth
Mandayam
Mandayam
Mandayam
Vibha
Jayanth
Jayanth
Mandayam
Mandayam
Mandayam
Vibha
Jayanth
Jayanth
Mandayam
Mandayam
Mandayam
name = "Vibha"
for letter in name:
print(letter)
V
i
b
h
a
# Sample dictionary
person = {
"first_name": "Vibha",
"middle_name": "Jayanth",
"last_name": "Mandayam",
"age": 15,
"city": "San Diego"
}
# Loop through each key and value
for key, value in person.items():
print(f"The key is '{key}' and the value is '{value}'. Hello!")
The key is 'first_name' and the value is 'Vibha'. Hello!
The key is 'middle_name' and the value is 'Jayanth'. Hello!
The key is 'last_name' and the value is 'Mandayam'. Hello!
The key is 'age' and the value is '15'. Hello!
The key is 'city' and the value is 'San Diego'. Hello!
# Define the correct password
correct_password = "codingiscool"
# Initialize a variable to control the while loop
is_correct = False
# While loop to ask for the password until the correct one is provided
while not is_correct:
# Ask the user for the password
user_input = input("Please enter your password: ")
# Check if the password is correct
if user_input == correct_password:
print("The password is correct!")
is_correct = True # Set condition to true to exit the loop
else:
print("Incorrect password. Please try again.")
Incorrect password. Please try again.
The password is correct!
# Ask the user for their name
user_name = input("Please enter your name: ")
# Iterate through the name and print each letter
for letter in user_name:
print(letter)
v
i
b
h
a
# List of fruits
fruits = ["Apple", "Banana", "Cherry", "Date", "Elderberry", "Fig", "Grape"]
# Iterate through the list of fruits and print each one
for fruit in fruits:
print(fruit)
Apple
Banana
Cherry
Date
Elderberry
Fig
Grape