# [ ] 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=["hawk", "robin", "bluejay", "mockingbird", "chicken"]
for bird in birds:
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=[1, 4, 5, 76, 2, 4, 52]
for num in player_points:
print(num*2)
2
8
10
152
4
8
104
# [ ] 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 birds:
long_string+=(bird+" ")
print(long_string)
hawk robin bluejay mockingbird chicken
# [ ] 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
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=[]
search_letter="a"
for city in cities:
if search_letter in city:
a_city.append(city)
else:
no_a_city.append(city)
print(a_city)
print(no_a_city)
['Shanghai', 'Dubai', 'São Paulo', 'Hyderabad']
['New York', 'Munich', 'Tokyo', 'Mexico 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)
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))
New York in default cities is True
New York in visitied_cites list is True
# [ ] complete paint stock
paint_colors = ["Red", "Green", "Blue", "Black", "Browm"]
def paint_stock():
color_request=input("What color paint are you looking for")
for color in paint_colors:
if color_request.title() in paint_colors:
print("Available")
break
else:
print("Not available!")
break
paint_stock()
Available
# [ ] 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"]
bone_guess
def footbone_quiz(bone_guess):
count=0
for i in range(2):
bone_guess=input("Name a foot bone:")
if bone_guess in foot_bones:
print("correct")
foot_bones.remove(bone_guess)
count+=1
print("You have identified",count,"bones!")
else:
print("Not found")
footbone_quiz(bone_guess)
correct
You have identified 1 bones!
Not found
# [ ] bonus version