1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
maria [59]
3 years ago
11

Assignment Background Video games have become an outlet for artists to express their creative ideas and imaginations and a great

source of entertainment for people who seek a fun and accessible ways to immerse in unique worlds while also share and interact with others. This project will print video game sales data for various platforms across the years. From the old school consoles like Atari 2600 and Sega Genesis to more modern ones like the Xbox One and PlayStation 4. Project Specifications You must implement the following functions: open_file() → file pointer: a. This function repeatedly prompts the user for a filename until the file is opened successfully. An error message should be shown if the file cannot be opened. It returns a file pointer. Use try-except and FileNotFoundError to determine if the file can be opened. Use the 'utf-8' encoding to open the file. fp = open (filename, encoding ='utf-8') b. Parameters: none c. Returns : file pointer main () : a) This function is the starting point of the program. The program starts by opening the file with the video game sales and reading the data into three dictionaries. The program will repeatedly prompt the user to select an option from the following menu: i. Option 1: Display the global sales for all video game titles across multiple platforms in a single year. Prompt for a year (validation is required!, year needs to be an int), get the data by calling the get_data_by_column function, and then display the selected year's data if the year exists in the data. Prompt the user whether they want to plot the data. If the answer is "y", use plot_global_sales ( ) to plot the histogram of the total global sales per publisher. ii. Option 2: Display the global sales for all video game titles across multiple years in a single platform. Prompt for a platform (validation is required!, cannot be a number) ), get the data by calling the get_data_by_column function, and then display the selected platform data if the platform exists in the data. Prompt the user whether they want to plot the data. If the answer is "y", get lists to plot by calling the get_totals function, and then use plot_global_sales () to plot the histogram of the total global sales per year. iii. Option 3: Display the regional sales for all video game genres. Prompt for a year (validation is required!, year needs to be an int), call get_genre_data, and then display the selected year data if the year exists using display_genre_data. Prompt the user whether they want to plot the data. If the answer is "y", call prepare_pie to get the lists to plot, and then use plot_genre_pie () to plot a pie chart of the total global sales per genre. iv. Option 4: Display the regional sales for all the video games by publisher. Prompt the user for a keyword in the publisher. Search for all publishers who have that keyword as a substring, then display the results. If there are multiple publisher names with the same string, enumerate all possible names. The publisher names should appears alphabetically because they were read into the dictionary that way; if not, sort them. Use the following string formatting: "{:<4d}{}", format (index, publisher) " Your header goes here import csv import pylab from operator import itemgetter def open_file(): WRITE DOCSTRING HERE! pass def read_file(fp): WRITE DOCSTRING HERE! pass def get_data_by_column (D1, indicator, c_value): WRITE DOCSTRING HERE! pass def get_publisher_data (D3, publisher): WRITE DOCSTRING HERE! pass def display_global_sales_data(L, indicator): WRITE DOCSTRING HERE! header1 = ['Name', 'Platform', 'Genre', 'Publisher', 'Global Sales'] header2 = ['Name', 'Year', 'Genre', 'Publisher', 'Global Sales'] pass def get_genre_data(D2, year): WRITE DOCSTRING HERE! pass def main(): # Menu options for the program MENU = '''Menu options 1) View data by year 2) View data by platform 3) View yearly regional sales by genre 4) View sales by publisher 5) Quit Enter choice: ". while choice != '5': #Option 1: Display all platforms for a single year try: #if the list of platforms for a single year is empty, show an error message pass except ValueError: print("Invalid year.") #Option 4: Display publisher data # Enter keyword for the publisher name # search all publisher with the keyword match = [] # print the number of matches found with the keywords if len (match) > 1: print("There are {} publisher(s) with the requested keyword!".format(len(match))). for i,t in enumerate (match): print("{:<4d}{}".format(i,t[0])) # PROMPT USER FOR INDEX else: index = 0 choice = input (MENU) print("\nThanks for using the program!") print("I'll leave you with this: "All your base are belong to us!"") if == "_main ": name main()

Computers and Technology
1 answer:
Sphinxa [80]3 years ago
7 0

Answer:

Code

import csv

def open_file():

try:

fname=input("Enter the filename to open (xxx.yyy): ")

fp=open(fname,encoding='utf-8')

return fp

except FileNotFoundError:

print("File not found! Please Enter correct filename with extension")

return open_file()

def read_file(fp):

fields = []

rows = []

csvreader = list(csv.reader(fp))

# skiped 1 row because it contains field name

fields = csvreader[0]

D1={}

D2={}

D3={}

# accessing the data of csv file

for line in csvreader[1:]:

name = line[0].lower().strip()

platform = line[1].lower().strip()

if line[2]!='N/A':

year = int(line[2])

else:

year=line[2]

genre = line[3].lower().strip()

publisher = line[4].lower().strip()

na_sales = float(line[5])

eur_sales = float(line[6])

jpn_sales = float(line[7])

other_sales = float(line[8])

global_sales=(na_sales+eur_sales+jpn_sales+other_sales)*1000000

if name not in D1:

D1[name]=[]

D1[name].append((name, platform, year, genre, publisher,global_sales))

if genre not in D2:

D2[genre]=[]

D2[genre].append((genre, year, na_sales, eur_sales,jpn_sales, other_sales, global_sales))

if publisher not in D3:

D3[publisher]=[]

D3[publisher].append((publisher, name, year, na_sales,eur_sales, jpn_sales, other_sales, global_sales))

# sorting

temp={}

# sorting keys

for Keys in sorted (D1) :

ls=D1[Keys]

ls=sorted(ls,key=lambda x: x[-1]) # sorting values

temp[Keys]=ls

D1=temp.copy()

temp={}

# sorting keys

for Keys in sorted (D2) :

ls=D2[Keys]

ls=sorted(ls,key=lambda x: x[-1]) # sorting values

temp[Keys]=ls

D2=temp.copy()

temp={}

# sorting keys

for Keys in sorted (D3) :

ls=D3[Keys]

ls=sorted(ls,key=lambda x: x[-1]) # sorting values

temp[Keys]=ls

D3=temp.copy()

return D1,D2,D3

 

def main():

fp=open_file()

D1,D2,D3=read_file(fp)

# displaying the row_count in dictionaries

cnt=0

for d in D1:

cnt+=1

print(cnt)

print("\n\n=============================================\n\n")

cnt=0

for d in D2:

cnt+=1

print(cnt)

print("\n\n=============================================\n\n")

cnt=0

for d in D3:

cnt+=1

print(cnt)

print("\n\n=============================================\n\n")

 

 

if __name__=="__main__":

main()

Explanation:

see code and see output attached

You might be interested in
Where to set up wireless network xbox one?
svlad2 [7]
Turn on your Xbox One and go to the Settings menu.

Select Network.

Select Set Up wireless network, to connect to a new network.

Xbox One asks Which one is yours? and displays the wireless networks it detects in your area.

Select the network you want to connect to.

4 0
3 years ago
If you play gta and don't know the song ''Glamorous'' Then what do you even do when you play?
Paraphin [41]
You literally don’t do anything you’re just like dead of sun
4 0
2 years ago
Read 2 more answers
Who is this person?<br><br><br> Kaneppeleqw. I see them everywhere. Are they a bot? Are they human?
Effectus [21]
I’m not sure. Maybe a human.
6 0
2 years ago
Ask how many apples the user wants. Ask how many people the user will share the apples with. Find out how many apples will remai
Sati [7]

Answer:

The program in Python is as follows:

apples = int(input("Apples: "))

people = int(input("People: "))

apples%=people

print("Remaining: ",apples)

Explanation:

This gets the number of apples

apples = int(input("Apples: "))

This gets the number of people to share the apple

people = int(input("People: "))

This calculates the remaining apple after sharing the apple evenly

apples%=people

This prints the calculated remainder

print("Remaining: ",apples)

5 0
3 years ago
Can anybody tell me how to screenshot on a PC with no "print screen" button?
Liono4ka [1.6K]

There is a extension from google chrome webstore that allows to take a screnshot

8 0
3 years ago
Other questions:
  • To go to a specific cell, press the function key
    9·1 answer
  • You have installed a point-to-point connection using wireless bridges and Omni directional antennas between two buildings. The t
    9·1 answer
  • Consider the concept of cultural lag. Identify two American values that are “lagging.” What are three norms that are lagging? Ho
    11·1 answer
  • Given a variable temps that refers to a list, all of whose elements refer to values of type float, representing temperature data
    10·2 answers
  • What's the main piece of information you look for in an e-mail message you're investigating??
    14·2 answers
  • Which technology has the potential to be misused to make atomic bombs? A. computer technology B. nuclear technology C. medical t
    14·1 answer
  • 1. Se requiere implementar un conversor unipolar que tendrá una tensión analógica variable entre 0 y 2 V pico. Deberá tener una
    10·1 answer
  • What is the output for this program?
    12·1 answer
  • 8. The cell reference for a range of cells that starts in cell A1 and goes over to column G and down to row 10 is, a. A1-G10 b.
    7·1 answer
  • In cells D6 through D8, enter formulas to calculate the values of the stocks. The formulas should multiply the number of shares
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!