# Noemi Cabrera
# 26 october 2021
# In this lesson, I learned to create lists by using square brackets [] and separating
# each item with commas. Lists can be made out of strings, integers, variables, or a
# mix of them. To access a specific item in a list you use string slicing that is zero
# based. So, the index count for the items starts at 0, not 1. Also, you can add
# different items once you slice them.
# I didn't have any difficulties in this lesson.
# [ The variable ft_bones is assigned a list made out of strings as its value. A list contains comma
# separated objects enclosed in square brackets. Then the type of the variable is displayed, which is
# list, by using type().] review and run example
# define list of strings
ft_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform", "intermediate cuneiform", "medial cuneiform"]
# display type information
print("ft_bones: ", type(ft_bones))
# print the list
print(ft_bones)
ft_bones: <class 'list'>
['calcaneus', 'talus', 'cuboid', 'navicular', 'lateral cuneiform', 'intermediate cuneiform', 'medial cuneiform']
# [ The variable age_survey is assigned a list made out of integers as its value. Then the type of the
# variable is displayed, which is list, by using type(). ] review and run example
# define list of integers
age_survey = [12, 14, 12, 29, 12, 14, 12, 12, 13, 12, 14, 13, 13, 46, 13, 12, 12, 13, 13, 12, 12]
# display type information
print("age_survey: ", type(age_survey))
# print the list
print(age_survey)
age_survey: <class 'list'>
[12, 14, 12, 29, 12, 14, 12, 12, 13, 12, 14, 13, 13, 46, 13, 12, 12, 13, 13, 12, 12]
# [ The variable mixed_list is assigned a list made out of strings, integers, and lists as its value.
# Even though the list has different data types, the type will still be list.] review and run example
# define list of mixed data type
mixed_list = [1, 34, 0.999, "dog", "cat", ft_bones, age_survey]
# display type information
print("mixed_list: ", type(mixed_list))
# print the list
print(mixed_list)
mixed_list: <class 'list'>
[1, 34, 0.999, 'dog', 'cat', ['calcaneus', 'talus', 'cuboid', 'navicular', 'lateral cuneiform', 'intermediate cuneiform', 'medial cuneiform'], [12, 14, 12, 29, 12, 14, 12, 12, 13, 12, 14, 13, 13, 46, 13, 12, 12, 13, 13, 12, 12]]
# [The team_names variable contains a list of strings that are team names. ] create
# team_names list and populate with 3-5 team name strings
team_names = ["Golden stars", "Rolling Stoners", "Full Spirit", "Rock for Life",
"Crafty Crew"]
# [ The list is printed by putting the variable containing the list in print()]
# print the list
print(team_names)
['Golden stars', 'Rolling Stoners', 'Full Spirit', 'Rock for Life', 'Crafty Crew']
# [ The list created contains both integers and strings separarted by commas.] Create
# a list mix_list with numbers and strings with 4-6 items
mix_list = [1, "bread", 2, "oranges", 5, "potatoes"]
# [ The variable mix_list contains the list created, therefore, the list is displayed. ]
# print the list
print(mix_list)
[1, 'bread', 2, 'oranges', 5, 'potatoes']
# [ Each item is separated with commas and they're counted starting with index 0.
# In this case, the index count of the 1st bone in the list ft_bones is 0.
# The 2nd bone is index 1, and so on. ] review and run example
print(ft_bones[0], "is the 1st bone on the list")
print(ft_bones[2], "is the 3rd bone on the list")
print(ft_bones[-1], "is the last bone on the list")
calcaneus is the 1st bone on the list
cuboid is the 3rd bone on the list
medial cuneiform is the last bone on the list
# [Here, the 2nd and 4th bone are accessed by writing their index count, which is 1 and
# 3. Both are used in the same sentence. ] review and run example
print(ft_bones[1], "is connected to the",ft_bones[3])
talus is connected to the navicular
# [ The sum of the first 3 ages is cointained in the variable three_ages. The ages are
# slices of the list found in age_survey. Then the sum of these ages is printed. ]
# review and run example
three_ages_sum = age_survey[0] + age_survey[1] + age_survey[2]
print("The first three ages total", three_ages_sum)
The first three ages total 38
# [ The variable streets contains a list of street names. ] Create a list, streets, that lists the name of 5 street name strings
streets = ["Main","Yellowsnow","Church","Maple", "Allen"]
# [ The first street name (index 0) is printed with the message that says it has no
# parking. ] print a message that there is "No Parking" on index 0 or index 4 streets
print(streets[0],"street: 'No Parking'")
Main street: 'No Parking'
# [ The variable num_2_add contains a list made out of 5 integers. ]
# Create a list, num_2_add, made of 5 different numbers between 0 - 25
num_2_add = [7, 8, 14, 19, 25]
# [The variable is sliced to access each integer in the list and then these are added
# using the + sign. ] print the sum of the numbers
print(num_2_add[0]+ num_2_add[1] + num_2_add[2] + num_2_add[3] + num_2_add[4])
73
# [ The error in this code is that the variable play_checks is not assigned a value before
# using it. Therefore, Python cannot do the sum. ] Review & Run, but ***Do Not Edit***
# this code cell
# [ ] Fix the error by only editing and running the block below
print(" Total of checks 3 & 4 = $", pay_checks[2] + pay_checks[3])
Execution error
NameError: name 'pay_checks' is not defined
# [ To fix the problem above, I assigned the pay_checks variable a list value made with
# integers. Then I placed the same code of above after I defined the variable to display
# the sum of the checks 3 & 4.] Fix the error above by creating and running code in
# this cell.
pay_checks = [110, 190, 260, 300, 100, 230]
print(" Total of checks 3 & 4 = $", pay_checks[2] + pay_checks[3])
Total of checks 3 & 4 = $ 560