Please reference the link below for the Abruptly Goblins Off-Platform project that I have a question about …
https://www.codecademy.com/courses/learn-python-3/informationals/python3-abruptly-goblins
My code for Step 10 (which is referenced in the Type Error message at the bottom of this post as Cell[113] …
def available_on_night(gamers_list, day):
attending = []
for gamer in gamers_list:
if day in gamer['availability']:
attending.append(gamer['name'])
return attending
attending_game_night = available_on_night(gamers, game_night)
print(attending_game_night)
My code for Step 13 (which is referenced in the TypeError message near the bottom of this post as Cell[129] …
def not_available_on_night(gamers_list, day):
attending = []
not_attending = []
for gamer in gamers_list:
if day in gamer['availability']:
attending.append(gamer['name'])
else:
not_attending.append(gamer['name'])
return not_attending
unable_to_attend_best_night = not_available_on_night(gamers, game_night)
#print(unable_to_attend_best_night)
second_night_availability = build_daily_frequency_table()
calculate_availability(unable_to_attend_best_night, second_night_availability)
second_night = find_best_night(second_night_availability)
I received the following Type Error messages:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[129], line 15
12 #print(unable_to_attend_best_night)
14 second_night_availability = build_daily_frequency_table()
---> 15 calculate_availability(unable_to_attend_best_night, second_night_availability)
16 second_night = find_best_night(second_night_availability)
Cell In[113], line 3, in calculate_availability(gamers_list, available_frequency)
1 def calculate_availability(gamers_list, available_frequency):
2 for gamer in gamers_list:
----> 3 for day in gamer['availability']:
4 available_frequency[day] += 1
TypeError: string indices must be integers
I’ve gone back to double check and run my code in Step 10 (Cell[113]) and the output is the correct list of six gamer names. I know my code is not nearly as succinct and elegant as the provided Codecademy solution but I’d still like to learn if it is possible to make my code work. I’d appreciate it if someone can help me understand where I went wrong. I’ve been sitting on this problem for several days now …
Thank you.