Question

Expected submission: 1 Python file, Graph_Data.py Make a file called Graph_data Inside this file create 3 functions: 1.) BarG

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The Code for Graph_Data.py is

from matplotlib import pyplot #used matplotlib to plot the graphs to install matplotlib use command "python -m pip install matplotlib" log = {"name":[],"category":[],"price":[]} #used hybrid(dictionary,lists) data structure as storage element """ BarGraph LineGraph SaveGraph Main Code Section """ def BarGraph(x_data,y_data,x_label,y_label,title): pyplot.bar(x_data,y_data) pyplot.xlabel(x_label) pyplot.ylabel(y_label) pyplot.title(title) pyplot.show() def LineGraph(x_data,y_data,x_label,y_label,title): pyplot.plot(x_data,y_data) pyplot.xlabel(x_label) pyplot.ylabel(y_label) pyplot.title(title) pyplot.show() def SaveGraph(x_data,y_data,x_label,y_label,title): pyplot.bar(x_data,y_data) pyplot.xlabel(x_label) pyplot.ylabel(y_label) pyplot.title(title) pyplot.savefig(title+".png") if __name__=="__main__": print("::Menu::") #printed the menu only once if you want it repeatedly place it in while loop print("1.Log a new item") print("2.Create a bar graph of the existing data") print("3.Create a line graph of the existing data") print("4.Save the existing data's graph") print("5.Exit") while True: #executes until 5.Exit option is selected opt = input("opt >> ") if opt == "1": #1.Logging a new item, (name,category,price) are stored in log data structure name = input("enter item name:") category = input("enter item category:") price = int(input("enter item price:")) log["name"].append(name) log["category"].append(category) log["price"].append(price) elif opt == "2": #2.Creating a bar graph with the existing log data query = input("based on 1.price or 2.category ?:") #based on selected ones graphing takes place if query=="1": BarGraph(log["name"],log["price"],"Names","Prices","Prices of Items") # Names vs Prices bar graph else: BarGraph(log["name"],log["category"],"Names","Categories","Categories of Items") # Names vs Categories bar graph elif opt == "3": query = input("based on 1.price or 2.category ?:") if query=="1": LineGraph(log["name"],log["price"],"Names","Prices","Prices of Items") # Names vs Prices line graph else: LineGraph(log["name"],log["category"],"Names","Categories","Categories of Items") # Names vs Categories line graph elif opt == "4": query = input("based on 1.price or 2.category ?:") if query=="1": SaveGraph(log["name"],log["price"],"Names","Prices","Prices of Items") # Names vs Prices bar graph is saved as png else: SaveGraph(log["name"],log["category"],"Names","Categories","Categories of Items") # Names vs Categories bar graph is saved as png elif opt == "5": #5.Exit - exiting the loop break else: #if any other input is placed it shows invalid option print("Invalid option") 

Explanation of the code is given in the comments section of the code. Please go through that and feel free to ask queries if any.

Sample output of the code:

Graphs produced from option 2 to 4 are

After entering the same data using option 1

choosing option 2 then 1 produces below graph

choosing option 2 then 2 produces below graph

choosing option 3 then 1 produces below graph

choosing option 3 then 2 produces below graph

choosing option 4 then 1 produces below graph

Entering option 5 exits the loop there by execution as well.

Thank you, feel to ask queries if any. Don't forget to like.

Add a comment
Know the answer?
Add Answer to:
Expected submission: 1 Python file, Graph_Data.py Make a file called Graph_data Inside this file create 3...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python 3 Define a function that uses two lists similar to the following to create a...

    python 3 Define a function that uses two lists similar to the following to create a dictionary: items = ['laptop', 'tablet', 'smartphone', 'reader', 'camera'] price = [749, 199, 399, 99, 1149] The dictionary should have the names of the items as keys and the prices as values. After creating the dictionary, ask the user to enter the name of an item, and display its price if the item is in the dictionary. If the item is not in the dictionary...

  • (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that...

    (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that you have been provided on Canvas. That file has a name and 3 grades on each line. You are to ask the user for the name of the file and how many grades there are per line. In this case, it is 3 but your program should work if the files was changed to have more or fewer grades per line. The name and...

  • I need help building code in python for this: Create a program that: Creates a sales...

    I need help building code in python for this: Create a program that: Creates a sales receipt, displays the receipt entries and totals, and saves the receipt entries to a file Prompt the user to enter the Item Name Item Quantity Item Price Display the item name, the quantity, and item price, and the extended price (Item Quantity multiplied by Item Price) after the entry is made Save the item name, quantity, item price, and extended price to a file...

  • Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create...

    Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create a completed program that prompts the user for the name of a data file, and reads the contents of that data file, then creates variables in a form suitable for computing the answer to some questions. The format should be in the same manner as the attached .py file. All subsequent assignment details (.py and .csv files) can be found at this...

  • Create a Python script file called hw12.py. Add your name at the top as a comment,...

    Create a Python script file called hw12.py. Add your name at the top as a comment, along with the class name and date. Ex. 1. a. Texting Shortcuts When people are texting, they use shortcuts for faster typing. Consider the following list of shortcuts: For example, the sentence "see you before class" can be written as "c u b4 class". To encode a text using these shortcuts, we need to perform a replace of the text on the left with...

  • Create a python script to manage a user list that can be modified and saved to...

    Create a python script to manage a user list that can be modified and saved to a text file. Input text file consisting of pairs of usernames and passwords, separated by a colon (:) without any spaces User choice: (‘n’-new user account, ‘e’-edit existing user account, ‘d’- delete existing user account, ‘l’- list user accounts, ‘q’-quit) List of user accounts, error messages when appropriate Output text file consisting of pairs of username and passwords, separated by a colon (:) without...

  • java Part 1 Create a NetBeans project that asks for a file name. The file should...

    java Part 1 Create a NetBeans project that asks for a file name. The file should contain an unknown quantity of double numeric values with each number on its own line. There should be no empty lines. Open the file and read the numbers. Print the sum, average, and the count of the numbers. Be sure to label the outputs very clearly. Read the file values as Strings and use Double.parseDouble() to convert them. Part 2 Create a NetBeans project...

  • Python 3 please and thank you Task 3: Create a Function 7 Create the function TotalRewardPoints...

    Python 3 please and thank you Task 3: Create a Function 7 Create the function TotalRewardPoints which accepts the dictionary that you created in Task 1 and a list of ticket purchases and displays the information as shown below. Ticket Purchase List is formatted as [Number of Tickets, Type of Ticket....] The total reward points a user gets is calculated by using the following formula: Reward Points = Number of Ticket Bought x Reward Points for that Ticket Type Your...

  • In Python and in one file please. (Simple functions with an expressions) Create a function called...

    In Python and in one file please. (Simple functions with an expressions) Create a function called load_inventory(filename). The filename argument in this case specifies the name of a file that contains all the inventory/product information for the store, including product names, descriptions, prices, and stock levels. This function should clear any information already in the product list (i.e., a fresh start) and then re-initialize the product list using the file specified by the filename argument. You can structure your file...

  • python 3 needs to read a local JSON file - it doesn't need to access the...

    python 3 needs to read a local JSON file - it doesn't need to access the internet. Write a class named NobelData that reads a JSON file containing data on Nobel Prizes and allows the user to search that data. It just needs to read a local JSON file - it doesn't need to access the internet. Specifically, your class should have an init method that reads the file, and it should have a method named search_nobel that takes as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT