# [x] review and run example
word = "cello"
for letter in word:
print(letter)
c
e
l
l
o
# [x] review and run example
# note: the variable 'letter' changed to 'item'
word = "trumpet"
for item in word:
print(item)
t
r
u
m
p
e
t
# [x] review and run example
# note: variable is now 'xyz'
# using 'xyz', 'item' or 'letter' are all the same result
word = "piano"
for xyz in word:
print(xyz)
p
i
a
n
o
# [x] review and run example
# creates a new string (new_name) adding a letter (ltr) each loop
# Q?: how many times will the loop run?
student_name = "Skye"
new_name = ""
for ltr in student_name:
if ltr.lower() == "y":
new_name += ltr.upper()
else:
new_name += ltr
print(student_name,"to",new_name)
Skye to SkYe
# [x] Get user input for first_name
# [x] iterate through letters in first_name
# - print each letter on a new line
first_name = input("enter your first name: ")
for letter in first_name:
print(letter)
J
e
s
u
s
# [x] Create capitalize-io
first_name = input("enter first name: ")
new_name = ""
for ltr in first_name:
if ltr.lower() == "i":
new_name += ltr.upper()
elif ltr.lower() == "o":
new_name += ltr.upper()
else:
new_name += ltr
print(first_name,"to", new_name)
olivia to OlIvIa
# [x] review and run example
student_name = "Skye"
for letter in student_name[:3]:
print(letter)
S
k
y
# Iterate BACKWARDS
# [x] review and run example
student_name = "Skye"
# start at "y" (student_name[2]), iterate backwards
for letter in student_name[2::-1]:
print(letter)
y
k
S
# [x] create & print a variable, other_word, made of every other letter in long_word
long_word = "juxtaposition"
for ltr in long_word[::2]:
print(ltr)
j
x
a
o
i
i
n
# Mirror Color
# [x] get user input, fav_color
# [x] print fav_color backwards + fav_color
# example: "Red" prints "deRRed"
fav_color = input("enter your fave color")
print(fav_color[::-1] + fav_color)
eulbblue