# [ ] 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
birds = ['Crow','Peacock','Dove','Sparrow','Ostrich','Pigeon']
for name in birds:
print(name)
# [ ] create a list of 7 integers: player_points
# [ ] print double the points for each point value
player_points = [5, 10, 15, 20, 25, 30, 35]
for point in player_points:
print(point*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 name in birds:
long_string += " " + name
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"
cities = ["New York", "Shanghai", "Munich", "Tokyo", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
for city in cities:
if city.lower().startswith("m"):
print(city)
else:
pass
# [ ] 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
cities = ["New York", "Shanghai", "Munich", "Tokyo", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
a_city = []
no_a_city = []
for city in cities:
if city.lower().startswith("a"):
a_city.append(city)
else:
no_a_city.append(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
def paint_search(search_color, paint_colors = ["Red","blue","purple", "pink", "white"] ):
for color in paint_colors:
if color == search_color.lower():
return "color found"
else:
pass
return "color not found"
color_request = input("Enter the paint color you need:").lower()
print(color_request, paint_search(color_request))
# [ ] Complete Foot Bones Quiz
# foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform",
# "intermediate cuneiform", "medial cuneiform"]
foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform", "intermediate cuneiform", "medial cuneiform"]
identified = 0
def bone_search(search_bone):
global identified
for bone in foot_bones:
if bone == search_bone.lower():
identified += bone.count(bone)
return "correct"
else:
pass
return "incorrect"
print("Is talus in the foor_bone list?:", bone_search("talus"))
print("Is distal in the foor_bone list?:", bone_search("distal"))
print("Total number of identified bones:", identified)
# [ ] bonus version