def printing_report(): print(reports.count_games("game_stat.txt")) print(reports.decide("game_stat.txt", "1998")) print(reports.get_latest("game_stat.txt")) print(reports.count_by_genre("game_stat.txt", "RPG")) print(reports.get_line_number_by_title("game_stat.tx", "World of Warcraft"))
def export_count_by_genre(prompt): with open("export.txt", "a") as file_handler: genre = input(prompt) file_handler.write("There is " + str(count_by_genre("game_stat.txt", genre)) + "games in the file under the " + str(genre) + " genre.\n\n")
def process_question(question): if question == "How many games are in the file?": answer = reports.count_games(FILE_NAME) print(answer) elif question == "Is there a game from a given year?": year = input("Which year?") answer = reports.decide(FILE_NAME, year) print(answer) elif question == "Which is the latest game?": answer = reports.get_latest(FILE_NAME) print(answer) elif question == "How many games are in the file by genre?": genre = input("Provide a genre:") answer = reports.count_by_genre(FILE_NAME, genre) print(answer) elif question == "What is the line number of a given title?": title = input("Provide a title:") answer = reports.get_line_number_by_title(FILE_NAME, title) print(answer) elif question == "Can you give me the alphabetically ordered list of the titles?": print("Yes, sure.") answer = reports.sort_abc(FILE_NAME) print(answer) elif question == "Which genres occur in the data file?": answer = reports.get_genres(FILE_NAME) print(answer) elif question == "What is the release year of the top sold first-person shooter game?": answer = reports.when_was_top_sold_fps(FILE_NAME) print(answer)
def printing(): fallback_file_name = "game_stat.txt" file_name = input("Which file should I analyze? (default: game_stat.txt) ") if not file_name: file_name = fallback_file_name try: file_name = check_file(file_name, fallback_file_name) except FileNotFoundError as e: print("No such file. Exiting...") else: print("1.", reports.count_games(file_name)) year = int(input("2. Which year? ")) print(" ", reports.decide(file_name, year)) print("3.", reports.get_latest(file_name)) genre = input("4. Which genre? ") print(" ", reports.count_by_genre(file_name, genre)) title = input("5. Which title? ") print(" ", reports.get_line_number_by_title(file_name, title)) # BONUS print("B-1. Sorted titles: ") for line in reports.sort_abc(file_name): print(" ", line) print("B-2. Genres:") for line in reports.get_genres(file_name): print(" ", line) print("B-3.", reports.when_was_top_sold_fps(file_name))
def test_4_count_by_genre(self): result = reports.count_by_genre(self.input_file, "First-person shooter") self.assertEqual(result, 6) if result == 6: self.points += 2 print("Function 'count_by_genre' is passed. 2 points.")
def main(file_name): # How many games are in the file? print_function("\nNumber of games in the file:", reports.count_games(file_name)) # bonus: What is the abc ordered list of titles? print_function("\nThese are the names of said games: ", reports.sort_abc(file_name)) # Which is the latest game? print_function("\nThe latest game in the file is:", reports.get_latest(file_name)) # What is the line number of the given title? try: print_function("The game's line number is: ", reports.get_line_number_by_title(file_name)) except ValueError: print("There's no game with that name in the file!") # Is there a game from a given year? print_function("There is at least one game from the given year:", reports.decide(file_name)) # bonus: What are the genres? print_function("\nThe following genres are in the file: ", reports.get_genres(file_name)) # How many games do we have by genre? print_function("Number of games in genre:", reports.count_by_genre(file_name)) # bonus: What is the release date of top sold fps shooter game? print_function("\nThe highest-selling RPG from the list was released in: ", reports.when_was_top_sold_fps(file_name))
def pprinter(file_name): pp = pprint.PrettyPrinter(indent=1, width=80, depth=None, stream=None) pp.pprint(reports.count_games('game_stat.txt')) pp.pprint(reports.decide('game_stat.txt', 2000)) pp.pprint(reports.get_latest('game_stat.txt')) pp.pprint(reports.count_by_genre('game_stat.txt', 'RPG')) pp.pprint(reports.get_line_number_by_title('game_stat.txt', 'Minecraft'))
def main(): year = int(input("Is there a game from (enter a year) or <press enter to skip>: ") or 1999) print("\n", reports.get_genres("game_stat.txt")) genre = input("Number of games from (enter a genre) or <press enter to skip>: ") or "RPG" print("\n", reports.sort_abc("game_stat.txt")) title = input("Line number of (enter a title) or <press enter to skip>: ") or "Minecraft" genre_list = reports.get_genres("game_stat.txt") title_list = reports.sort_abc("game_stat.txt") with open("report-results.txt", mode="w", encoding="UTF-8") as export_file: export_file.write("Game count: " + str(reports.count_games("game_stat.txt")) + "\n\n") export_file.write("Is there a game from " + str(year) + ": ") export_file.write(str(reports.decide("game_stat.txt", year)) + "\n\n") export_file.write("Latest game: " + str(reports.get_latest("game_stat.txt")) + "\n\n") export_file.write("Number of " + genre + " games: ") export_file.write(str(reports.count_by_genre("game_stat.txt", genre)) + "\n\n") export_file.write("Line number of " + title + ": ") export_file.write(str(reports.get_line_number_by_title("game_stat.txt", title)) + "\n\n") export_file.write("Ordered titles: \n") export_file.write("" .join(game + ", " for game in title_list if game != title_list[-1]) + title_list[-1] + "\n\n") # Puts a comma between each title before writing to the file export_file.write("Genres: ") export_file.write("" . join(genre + ", " for genre in genre_list if genre != genre_list[-1]) + genre_list[-1] + "\n\n") export_file.write("Release date of top-sold FPS: ") export_file.write(str(reports.when_was_top_sold_fps("game_stat.txt")) + "\n\n")
def export(answer): filename = open("export.txt", "w") filename.write(str(reports.count_games(answer)) + "\n") filename.write(str(reports.decide(answer, 1998)) + "\n") filename.write(str(reports.get_latest(answer)) + "\n") filename.write(str(reports.count_by_genre(answer, "RPG")) + "\n") filename.write( str(reports.get_line_number_by_title(answer, "StarCraft")) + "\n")
def exporting_results(file_name): with open("game_statistics_export.txt", "w") as export_file: export_file.write(str(r.count_games(file_name)) + "\n") export_file.write(("True" if is_game_in_year else "False") + "\n") export_file.write(str(r.get_latest(file_name)) + "\n") export_file.write(str(r.count_by_genre(file_name, genre)) + "\n") export_file.write( str(r.get_line_number_by_title(file_name, title)) + "\n")
def export_count_by_genre(): """Export to file: how many games is by genre.""" genre = input("Please. give me a genre of game: ") genres = reports.count_by_genre(filename, genre) message = "We have {} games from {} genre.".format(genres, genre) export_to_file(message) print("DATA TRANSFERRED TO A FILE: exported_answers.txt!\n")
def main(): print(count_games()) print(decide("game_stat.txt", 2004)) print(get_latest()) print(count_by_genre()) print(get_line_number_by_title()) print(sort_abc()) print(get_genres()) print(when_was_top_sold_fps())
def print_count_by_genre(file_name="game_stat.txt"): genre = input( "Enter a genre to see how many games of that type there are in the data: " ) count = reports.count_by_genre(file_name, genre) ans = "The file contains {n} games in the genre \'{g}\'.".format(n=count, g=genre) print(ans) return ans
def export_answers(file_name='new_file.txt'): with open(file_name, "w") as txt: lines_of_text = [str(reports.count_games('game_stat.txt')), \ str(reports.decide('game_stat.txt', '2000')),\ reports.get_latest('game_stat.txt'), \ str(reports.count_by_genre('game_stat.txt', 'RPG')), \ str(reports.get_line_number_by_title('game_stat.txt', 'Doom 3'))] for item in lines_of_text: txt.write('%s\n' % item)
def print_the_answers(file_name, year, genre, title): print(reports.count_games(file_name)) print(reports.decide(file_name, year)) print(reports.get_latest(file_name)) print(reports.count_by_genre(file_name, genre)) print(reports.get_line_number_by_title(file_name, title)) print(reports.sort_abc(file_name)) print(reports.get_genres(file_name)) print(reports.when_was_top_sold_fps(file_name))
def main(): print(reports.count_games("game_stat.txt"), reports.decide("game_stat.txt", 2012), reports.get_latest("game_stat.txt"), reports.count_by_genre("game_stat.txt", "RPG"), reports.get_line_number_by_title("game_stat.txt", "Diablo III"), reports.sort_abc("game_stat.txt"), reports.get_genres("game_stat.txt"), reports.when_was_top_sold_fps("game_stat.txt"), sep="\n")
def printing_reports(): import reports print(reports.count_games("game_stat.txt")) print(reports.decide("game_stat.txt", "2012")) print(reports.get_latest("game_stat.txt")) print(reports.count_by_genre("game_stat.txt", "Real-time strategy")) print(reports.get_line_number_by_title("game_stat.txt", "Counter-Strike: Condition Zero")) print(reports.sort_abc("game_stat.txt")) print(reports.get_genres("game_stat.txt")) print(reports.when_was_top_sold_fps("game_stat.txt"))
def count_by_genre(file_name): genre = input("What genre are you looking for? ") count_of_searched_genre = reports.count_by_genre(file_name, genre) print('') #blank line if count_of_searched_genre == 1: print(f"Searched genre came up {count_of_searched_genre} time.") if count_of_searched_genre == 0: print(f"Searched genre is not in a file") else: print(f"Searched genre came up {count_of_searched_genre} times.")
def export_to_txt(file_name, year, genre, title, exp_file="answers.txt"): with open(exp_file, "w") as text_file: text_file.write("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}".format( str(reports.count_games(file_name)), str(reports.decide(file_name, year)), str(reports.get_latest(file_name)), str(reports.count_by_genre(file_name, genre)), str(reports.get_line_number_by_title(file_name, title)), str(reports.sort_abc(file_name)), str(reports.get_genres(file_name)), str(reports.when_was_top_sold_fps(file_name))))
def export(): fw = open("reports.txt", "w") fw.writelines([ str(r.count_games("game_stat.txt")) + "\n", str(r.decide("game_stat.txt", 2000)) + "\n", str(r.get_latest("game_stat.txt")) + "\n", str(r.count_by_genre("game_stat.txt", "Real-time strategy")) + "\n", str(r.get_line_number_by_title("game_stat.txt", "Minecraft")) + "\n", str(r.sort_abc("game_stat.txt")) + "\n", str(r.get_genres("game_stat.txt")) + "\n", str(r.when_was_top_sold_fps("game_stat.txt")) + "\n" ])
def execute_function(number, datafile): if number == COUNT_GAMES_NUMER: return reports.count_games(datafile) if number == DECIDE_NUMBER: return reports.decide(datafile, ask_for_a_year()) if number == GET_LATEST_NUMBER: return reports.get_latest(datafile) if number == COUNT_BY_GENRE_NUMBER: return reports.count_by_genre(datafile, ask_for_genre())
def get_answers(inputs): file_name, year, genre, title = inputs """Returns a single string for the file exporter""" answers = (str(reports.count_games(file_name)) + "\n" + str(reports.decide(file_name, year)) + "\n" + reports.get_latest(file_name) + "\n" + str(reports.count_by_genre(file_name, genre)) + "\n" + str(reports.get_line_number_by_title(file_name, title)) + "\n" + ", ".join(reports.sort_abc(file_name)) + "\n" + ", ".join(reports.get_genres(file_name)) + "\n" + str(reports.when_was_top_sold_fps(file_name)) + "\n") return answers
def export_reports_answers(file_name, title, year, genre, export_file="export_reports.txt"): file = open(export_file, "w") file.write("The number of games in the file: {}\n".format(reports.count_games(file_name))) file.write("There is a game from a given year: {}\n".format(reports.decide(file_name, year))) file.write("The latest game is: {}\n".format(reports.get_latest(file_name))) file.write("The number of games we have by the given genre: {}\n".format(reports.count_by_genre(file_name, genre))) file.write("The line number of the given game is: {}\n".format(reports.get_line_number_by_title(file_name, title))) file.write("The alphabetical ordered list of the titles is: {}\n".format(reports.sort_abc(file_name))) file.write("The genres are: {}\n".format(reports.get_genres(file_name))) file.write("The release date of the top sold First-person shooter game is: {}\n".format(reports.when_was_top_sold_fps(file_name))) file.close() return export_file
def export_file(file_name): file = open(file_name, "w", newline='') writer = csv.writer(file, quoting=csv.QUOTE_MINIMAL) data = [ reports.count_games("game_stat.txt"), reports.decide("game_stat.txt", 2000), reports.get_latest("game_stat.txt"), reports.count_by_genre("game_stat.txt", "RPG"), reports.get_line_number_by_title("game_stat.txt", "Terraria") ] for answer in data: writer.writerow([answer]) file.close()
def export(file_name): with open(file_name, "w") as f: f.write(str(reports.count_games("game_stat.txt"))) f.write("\n") f.write(str(reports.decide("game_stat.txt", "1998"))) f.write("\n") f.write(str(reports.get_latest("game_stat.txt"))) f.write("\n") f.write(str(reports.count_by_genre("game_stat.txt", "RPG"))) f.write("\n") f.write( str( reports.get_line_number_by_title("game_stat.txt", "World of Warcraft")))
def main(): output = open('output.txt', 'w') output.write(str(reports.count_games('game_stat.txt'))) output.write('\n') output.write(str(reports.decide('game_stat.txt', 2000))) output.write('\n') output.write(reports.get_latest('game_stat.txt')) output.write('\n') output.write(str(reports.count_by_genre('game_stat.txt', 'RPG'))) output.write('\n') output.write( str(reports.get_line_number_by_title('game_stat.txt', 'Crysis'))) return
def export_the_reports(export_file_name, file_name, year, genre, title): results = [ reports.count_games(file_name), reports.decide(file_name, year), reports.get_latest(file_name), reports.count_by_genre(file_name, genre), reports.get_line_number_by_title(file_name, title), reports.sort_abc(file_name), reports.get_genres(file_name), reports.when_was_top_sold_fps(file_name) ] with open(export_file_name, "w") as export_file: for item in results: export_file.write("%s\n" % item)
def export_to_file(file_name="export.txt"): answers = [] answers.append(count_games()) answers.append(decide("game_stat.txt", 1998)) answers.append(get_latest()) answers.append(count_by_genre()) answers.append(get_line_number_by_title()) answers.append(sort_abc()) answers.append(get_genres()) answers.append(when_was_top_sold_fps()) with open(file_name, "w") as file_export: for i in answers: i = str(i) file_export.write(i) file_export.write("\n")
def export_report(file): filename = open("export_report.txt", "w") filename.write(str(reports.count_games(file)) + "\n") filename.write(str(reports.decide(file, 2005)) + "\n") filename.write(str(reports.get_latest(file)) + "\n") filename.write(str(reports.count_by_genre(file, "eh")) + "\n") filename.write( str(reports.get_line_number_by_title(file, "Diablo III")) + "\n") filename.write(str(reports.get_genres(file)) + "\n") filename.write(str(reports.get_most_played) + "\n") filename.write(str(reports.sum_sold("game_stat.txt")) + "\n") filename.write(str(reports.get_selling_avg("game_stat.txt")) + "\n") filename.write(str(reports.count_longest_title("game_stat.txt")) + "\n") filename.write(str(reports.get_date_avg("game_stat.txt")) + "\n") pass
def judy_answers(): file = open("game_stat_answers.txt", "w") file.write(str(reports.count_games("game_stat.txt"))) file.write("\n") file.write(str(reports.decide("game_stat.txt", "1999"))) file.write("\n") file.write(str(reports.get_latest("game_stat.txt"))) file.write("\n") file.write(str(reports.count_by_genre("game_stat.txt", "Real-time strategy"))) file.write("\n") file.write(str(reports.get_line_number_by_title("game_stat.txt", "Counter-Strike: Condition Zero"))) file.write("\n") file.write(str(reports.sort_abc("game_stat.txt"))) file.write("\n") file.write(str(reports.get_genres("game_stat.txt"))) file.write("\n")
import reports '''file_name = 'game_stat.txt' year = 2000 genre = "First-person shooter" title = "Counter-Strike"''' # uncomment for testing report = open("report.txt", "w") report.write(str(reports.count_games(file_name)) + "\n") report.write(str(reports.decide(file_name, year)) + "\n") report.write(str(reports.get_latest(file_name)) + "\n") report.write(str(reports.count_by_genre(file_name, genre)) + "\n") report.write(str(reports.get_line_number_by_title(file_name, title)) + "\n") report.write(str(reports.sort_abc(file_name)) + "\n") report.write(str(reports.get_genres(file_name)) + "\n") report.write(str(reports.when_was_top_sold_fps(file_name)) + "\n") report.close()
import reports '''file_name = 'game_stat.txt' year = 2000 genre = "First-person shooter" title = "Counter-Strike"''' # uncomment for testing print(reports.count_games(file_name)) print(reports.decide(file_name, year)) print(reports.get_latest(file_name)) print(reports.count_by_genre(file_name, genre)) print(reports.get_line_number_by_title(file_name, title)) print(reports.sort_abc(file_name)) print(reports.get_genres(file_name)) print(reports.when_was_top_sold_fps(file_name))
print ("5: Number of the given name") menu = input("Type in the number of the desired option from above, or anything else to quit:\n") try: menu = int(menu) except: print ("Quit!") break if menu > 5 or menu < 1: print ("Quit!") break if menu == 1: file.write("Number of games: " + str(reports.count_games(filename)) + "\n") elif menu == 2: year = input("Which year?: ") try: year = int(year) except: print ("Invalid argument given!") break file.write("Is there a game from " + str(year) + ": " + str(reports.decide(filename, year)) + "\n") elif menu == 3: file.write("Latest game: " + reports.get_latest(filename) + "\n") elif menu == 4: genre = input("Which genre?: ") file.write("Number of " + genre + " games: " + str(reports.count_by_genre(filename, genre)) + "\n") elif menu == 5: title = input("Which game?: ") file.write("Number of " + title + ": " + str(reports.get_line_number_by_title(filename, title)) + "\n") print ("Exported!\n") file.close()