English:
#How many games are there grouped by genre?
#Expected name of the function: count_grouped_by_genre(file_name)
#Expected output of the function: a dictionary with this structure: { [genre] : [count] }
#Detailed description: return a dictionary where each genre is associated with the count of the games of its genre
Polish:
Ile gier jest pogrupowanych według gatunków?
Wyświetlana nazwa funkcji: count_grouped_by_genre (file_name)
Wyświetlane wyniki funkcji: słownik o tej strukturze: {[gatunek]: [liczba]}
Szczegółowy opis: zwróć słownik, w którym każdy gatunek jest powiązany z liczbą gier swojego gatunku
Napisałem taką funkcję:
```def count_grouped_by_genre(file_name):
genres = []
dictionary = {}
count = 0
with open(file_name, 'rt') as file:
for line in file.readlines():
line= line.split("\t")
genres.append(line[3])
print(genres)
for key, value in dictionary.items():
for i in range(0, len(genres)):
#value = count[i]
if genres[i] == "Survival game":
#count += 1
dictionary[key] += 1
elif genres[i] == "RPG":
count += 1
elif genres[i] == "Action-adventure":
count += 1
elif genres[i] == "First-person shooter":
count += 1
elif genres[i] == "Simulation":
count += 1
elif genres[i] == "Real-time strategy":
count += 1
elif genres[i] == "Sandbox":
count += 1
#print(str(key) + " : " + str(value))
print(dictionary)
#for key, value in dictionary.items():
# print(str(key) + ":" + str(value))
#return dictionary
Pomoglibyście mi ją dokończyć?
Dołączam plik game_stat.txt z informacjami nt. gier.
- game_stat.txt (1 KB) - ściągnięć: 168