# [ ] review and run example
cities = ["New York", "Shanghai", "Munich", "Tokyo", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
for city in cities:
print(city)
# [ ] 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)
# [ ] 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)
# [ ] 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)
# [ ] 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)
# [ ] 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)
# [ ] 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)
# [ ] 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)
# [ ] 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)
# [ ] 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)
# [ ] 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)
# [ ] 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))
# [ ] 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)
# [ ] 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")
"# [ ] bonus version