# [ ] review and run example
word = "cello"
for letter in word:
print(letter)
c
e
l
l
o
# [ ] 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
# [ ] 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
# [ ] 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
# [ ] Get user input for first_name
# [ ] iterate through letters in first_name
# - print each letter on a new line
first_name=input("Please, enter your first name:").title()
for character in first_name:
print(character)
B
r
a
e
d
e
n
# [ ] Create capitalize-io
first_name=input("What is your first name?")
new_name = ""
for letter in first_name:
if letter.lower()=="o":
new_name+=letter.upper()
elif letter.lower()=="i":
new_name+=letter.upper()
else:
new_name+=letter
print(new_name)
wOrd
# [ ] review and run example
student_name = "Skye"
for letter in student_name[:3]:
print(letter)
S
k
y
# Iterate BACKWARDS
# [ ] 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
# [ ] create & print a variable, other_word, made of every other letter in long_word
long_word = "juxtaposition"
other_word=""
for letter in long_word[::2]:
other_word+=letter
print(other_word)
jxaoiin
# Mirror Color
# [ ] get user input, fav_color
# [ ] print fav_color backwards + fav_color
# example: "Red" prints "deRRed"
fav_color=input("What is your favorite color?")
color_choice=""
for letter in fav_color[::-1]:
color_choice+=letter
print(color_choice+fav_color)
print(fav_color[::-1]+fav_color)
eulBBlue
eulBBlue