# [ ] review and run example - note the first element is always index = 0
student_name = "Alton"
print(student_name[0], "<-- first character at index 0")
print(student_name[1])
print(student_name[2])
print(student_name[3])
print(student_name[4])
# [ ] review and run example
student_name = "Jin"
if student_name[0].lower() == "a":
print('Winner! Name starts with A:', student_name)
elif student_name[0].lower() == "j":
print('Winner! Name starts with J:', student_name)
else:
print('Not a match, try again tomorrow:', student_name)
# [ ] review and run ERROR example
# cannot index out of range
student_name = "Tobias"
# [ ] assign a string 5 or more letters long to the variable: street_name
# [ ] print the 1st, 3rd and 5th characters
street_name = "Heatedstreet"
print(street_name[0])
print(street_name[2])
print(street_name[4])
# [ ] Create an input variable: team_name - ask that second letter = "i", "o", or "u"
# [ ] Test if team_name 2nd character = "i", "o", or "u" and print a message
# note: use if, elif and else
team_name = input('Second letter should = "i", "o", or "u"')
if team_name.isalpha():
if team_name[1] == "i":
print('Second letter is "i"')
elif team_name[1] == "o":
print('Second letter is "o"')
elif team_name[1] == "u":
print('Second letter is "u"')
else:
print('Put a team that has "i", "o", or "u" as their second letter.')
else:
pass
# [ ] review and run example
student_name = "Joana"
# get last letter
end_letter = student_name[-1]
print(student_name,"ends with", "'" + end_letter + "'")
# [ ] review and run example
# get second to last letter
second_last_letter = student_name[-2]
print(student_name,"has 2nd to last letter of", "'" + second_last_letter + "'")
# [ ] review and run example
# you can get to the same letter with index counting + or -
print("for", student_name)
print("index 3 =", "'" + student_name[3] + "'")
print("index -2 =","'" + student_name[-2] + "'")
# [ ] assign a string 5 or more letters long to the variable: street_name
# [ ] print the last 3 characters of street_name
street_name = "johnston avenue"
print(street_name[12:15:])
# [ ] create and assign string variable: first_name
first_name = "Gerald"
# [ ] print the first and last letters of name
print(first_name[0],first_name[-1])
# [ ] Review, Run, Fix the error using string index
shoe = "tennis"
# print the last letter
print(shoe[-1])