# [ ] 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"
print(student_name[6])
# [ ] assign a string 5 or more letters long to the variable: street_name
# [ ] print the 1st, 3rd and 5th characters
street_name = "asdfg"
print(street_name[::2])
# [ ] 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("Type a word in which the second letter is \"i\", \"o\", or \"u.\": ")
if team_name[1] == "i":
print("correct")
elif team_name[1] == "o":
print("correct")
elif team_name[1] == "u":
print("correct")
else:
team_name = input("Type a word in which the second letter is \"i\", \"o\", or \"u.\": ")
# [ ] 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 = "qwerty"
print(street_name[-3:])
# [ ] create and assign string variable: first_name
first_name = "joe"
# [ ] 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])