Python3-Off platform project - error (function object not subscriptable)

In one function you add 1 to the available_frequency[day]
I checked the solution and that was the same. The error is about adding 1 to the amount of frequency. Why does it not work?
TypeError: ‘function’ object is not subscriptable


You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

We will need to see your code to examine this further.

Here’s the code. I copied it to memo as text


#checking that the gamer has a name and availability
def add_gamer(gamer, gamers_list):
if gamer.get(‘name’) and gamer.get(‘availability’):
print(“Use name and availability in gamer info.”)

#adding gamers
kimberly={‘name’:“Kimberly Warner”,‘availability’: [“Mondays”, “Tuesdays”, “Fridays”]}
add_gamer(kimberly, gamers)

add_gamer({‘name’:‘Thomas Nelson’,‘availability’: [“Tuesday”, “Thursday”, “Saturday”]}, gamers)
add_gamer({‘name’:‘Joyce Sellers’,‘availability’: [“Monday”, “Wednesday”, “Friday”, “Saturday”]}, gamers)
add_gamer({‘name’:‘Michelle Reyes’,‘availability’: [“Wednesday”, “Thursday”, “Sunday”]}, gamers)
add_gamer({‘name’:‘Stephen Adams’,‘availability’: [“Thursday”, “Saturday”]}, gamers)
add_gamer({‘name’: ‘Joanne Lynn’, ‘availability’: [“Monday”, “Thursday”]}, gamers)
add_gamer({‘name’:‘Latasha Bryan’,‘availability’: [“Monday”, “Sunday”]}, gamers)
add_gamer({‘name’:‘Crystal Brewer’,‘availability’: [“Thursday”, “Friday”, “Saturday”]}, gamers)
add_gamer({‘name’:‘James Barnes Jr.’,‘availability’: [“Tuesday”, “Wednesday”, “Thursday”, “Sunday”]}, gamers)
add_gamer({‘name’:‘Michel Trujillo’,‘availability’: [“Monday”, “Tuesday”, “Wednesday”]}, gamers)

#making a list of days
def build_daily_frequency_table():
frequency_table={‘Monday’: 0, ‘Tuesday’:0, ‘Wednesday’:0, ‘Thursday’:0, ‘Friday’:0, ‘Saturday’:0, ‘Sunday’:0}
return frequency_table

count_availability = build_daily_frequency_table

#this is not working - cannot add to frequency, cannot print

#adding frequency

def calculate_availability(gamers_list, available_frequency):
for gamer in gamers_list:
for day in gamer[‘availability’]:
available_frequency[day] += 1

calculate_availability(gamers, count_availability)

#best day - most players
def find_best_night(availability_table):
for day, availability in availability_table.items():
if availability>best_availability:
best_availability = availability
return best_night

#print the best day
#jupyter: the dictionary does not have “values” - changed the code according to solution
game_night = find_best_night(count_availability)

#fetch the gamers of the game night

def available_on_night(gamers_list,day):
return [gamer for gamer in gamers_list if day in gamer[‘availability’]]

attending_game_night = available_on_night(gamers, game_night)

#making the email for players

form_email = “”"
Hello {name}!

We are hosting a game night on {day_of_week}.

The game: {game} will be played then. Welcome!"""

#a function to fill in the form
def send_email(gamers_who_can_attend, day, game):
for gamer in gamers_who_can_attend:
print(form_email.format(name=gamer[‘name’], day_of_week=day, game=game))

send_email(attending_game_night, game_night, “Abruptly Goblins!”)

#next group / just copied the solution:
unable_to_attend_best_night = [gamer for gamer in gamers if game_night not in gamer[‘availability’]]
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)

available_second_game_night = available_on_night(gamers, second_night)
send_email(available_second_game_night, second_night, “Abruptly Goblins!”)

Please view the following linked FAQ especially the section on formatting code (or consider adding it as a github gist or pastebin etc. if it’s big), it makes it much easier to read.

Function not subsriptable suggests you’ve tried to use a function in a way it doesn’t support, namely function[]. Double check you’ve not mistakenly used (by typo) or otherwise any of the names defined as functions def name or accidentally passed a function instead of called it function vs. function().

Not the error, perhaps, but did you mean to invoke that function?

Yes, that was the idea. I try to check the code later today.

  • Tarja

and my first gamer availability_days was in plural “mondays”, it should have been “monday”.

Funny stuff, thanks anyway!