# [ ] review and run example
cities = ["New York", "Shanghai", "Munich", "Tokyo", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
for city in cities:
print(city)
New York
Shanghai
Munich
Tokyo
Dubai
Mexico City
São Paulo
Hyderabad
# [ ] review and run example
sales = [6, 8, 9, 11, 12, 17, 19, 20, 22]
total = 0
for sale in sales:
total += sale
print("total sales:", total)
total sales: 124
# [ ] review and run example
sales = [6, 8, 9, 11, 12, 17, 19, 20, 22]
total = 0
for dollars in sales:
total += dollars
print("total sales:", total)
total sales: 124
# [ ] create a list of 4 to 6 strings: birds
# print each bird in the list
bird_list = ["hawk", "robin", "bluejay", "mockingbird", "chicken"]
for bird in bird_list:
print(bird)
hawk
robin
bluejay
mockingbird
chicken
# [ ] create a list of 7 integers: player_points
# [ ] print double the points for each point value
player_points = [7, 14, 20, 26, 33, 36, 42]
for points in player_points:
print(points*2)
14
28
40
52
66
72
84
# [ ] create long_string by concatenating the items in the "birds" list previously created
# print long_string - make sure to put a space betweeen the bird names
long_string = ""
for bird in bird_list:
long_string += bird
print(long_string)
hawkrobinbluejaymockingbirdchicken
# [ ] review and run example of sorting into strings to display
foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform",
"intermediate cuneiform", "medial cuneiform"]
longer_names = ""
shorter_names = ""
for bone_name in foot_bones:
if len(bone_name) < 10:
shorter_names += "\n" + bone_name
else:
longer_names += "\n" + bone_name
print(shorter_names)
print(longer_names)
calcaneus
talus
cuboid
navicular
lateral cuneiform
intermediate cuneiform
medial cuneiform
# [ ] review and run example of sorting into lists
foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform",
"intermediate cuneiform", "medial cuneiform"]
longer_names = []
shorter_names = []
for bone_name in foot_bones:
if len(bone_name) < 10:
shorter_names.append(bone_name)
else:
longer_names.append(bone_name)
print(shorter_names)
print(longer_names)
['calcaneus', 'talus', 'cuboid', 'navicular']
['lateral cuneiform', 'intermediate cuneiform', 'medial cuneiform']
# [ ] Using cities from the example above iterate throught the list using "for"/"in"
# [ ] Print only cities starting with "m"
for city in cities[2:8:3]:
print(city)
Munich
Mexico City
# [ ] Using cities from the example above iterate throught the list using "for"/"in"
# cities = ["New York", "Shanghai", "Munich", "Tokyo", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
# [ ] sort into lists with "A" in the city name and without "A" in the name: a_city & no_a_city
a_city = []
no_a_city = []
str(cities).find("a")
for city in cities:
if "a" in cities:
a_city += city
else:
no_a_city += city
print(a_city)
print(no_a_city)
[]
['N', 'e', 'w', ' ', 'Y', 'o', 'r', 'k', 'S', 'h', 'a', 'n', 'g', 'h', 'a', 'i', 'M', 'u', 'n', 'i', 'c', 'h', 'T', 'o', 'k', 'y', 'o', 'D', 'u', 'b', 'a', 'i', 'M', 'e', 'x', 'i', 'c', 'o', ' ', 'C', 'i', 't', 'y', 'S', 'ã', 'o', ' ', 'P', 'a', 'u', 'l', 'o', 'H', 'y', 'd', 'e', 'r', 'a', 'b', 'a', 'd']
# [ ] review and run example
# iterates the "cities" list, count & sum letter "a" in each city name
cities = ["New York", "Shanghai", "Munich", "Tokyo", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
search_letter = "a"
total = 0
for city_name in cities:
total += city_name.lower().count(search_letter)
print("The total # of \"" + search_letter + "\" found in the list is", total)
The total # of "a" found in the list is 6
# [ ] review and run example
# city_search function has a default list of cities to search
def city_search(search_item, cities = ["New York", "Shanghai", "Munich", "Tokyo"] ):
for city in cities:
if city.lower() == search_item.lower():
return True
else:
# go to the next item
pass
# no more items in list
return False
# a list of cities
visited_cities = ["New York", "Shanghai", "Munich", "Tokyo", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
search = input("enter a city visited: ")
# Search the default city list
print(search, "in default cities is", city_search(search))
# search the list visited_cities using 2nd argument
print(search, "in visitied_cites list is", city_search(search,visited_cities))
Raleigh in default cities is False
Raleigh in visitied_cites list is False
# [ ] complete paint stock
paint_colors = ["Red", "Orange", "Yellow", "Green", "Blue", "Purple"]
color_request = []
for color in paint_colors:
color_request += paint_colors
break
print(color_request)
['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Purple']
# [ ] Complete Foot Bones Quiz
# foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform",
# "intermediate cuneiform", "medial cuneiform"]
def bone_structure(foot_bones_match):
foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform", "intermediate cuneiform", "medial cuneiform"]
for bones in foot_bones:
if bones in foot_bones:
print("correct")
break
else:
print("incorrect")
bone_structure("cuboid")
bone_structure("ankle")
correct
correct
"# [ ] bonus version
There’s an error in this block
Try running the app again, or contact the app’s creator