Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help to incorporate step #3 into my program. I do not know how to use JSON import. I also will like to streamline

I need help to incorporate step #3 into my program. I do not know how to use JSON import. I also will like to streamline the program some more. It is somewhat messy

Here are the assignment details for more clarity.

In a previous assignment,Favorite Languages Poll, you created a survey to poll users and ask what their favorite language was. Respondent names and responses were stored as key-value pairs in a dictionary. Begin with your assignment submission and modify it to do the following:

  • 1) On start, begin by checking to see if a data file exists (filename specified by you) and loading the contents of that file (json.load()) into the responses dictionary (3 points). If a file does not exist yet (the first time you run the program), design a new blank dictionary to store the responses (2 points).
  • 2) Use the loop you built from theFavorite Languages Pollassignment to get responses from input until the user is finished (5 points).
  • 3) After the user decides they are finished inputting responses and the report of responses displays, save the dictionary (json.dump()) to your file (3 points). Note: you will need to open the file in "write" mode and not "append" mode (2 points). You want to write the full contents of your dictionary since it should already contain previous responses. Append mode would write multiple dictionaries to the file and cause issues.

Note: you only need to submit your python file for this. The data file will be created after running your program for the first time.

HERE IS MY BROKEN PROGRAM

import json filename = 'programming_poll.txt' responses = [] language = [] fav_language = {} while True: response = input(" What is your name? ") language = input("What is the favorite programming language? ") responses.append(response) continue_poll = input("Would you like to add another response? (yes/no) ") if continue_poll != 'y': break with open(filename, 'w') as f: json.dump(response,f) for response in responses: f.write(f"{response} ") for language in language: f.write(f"{language} ") print(" --- Favorite Programming Languages ---") print(f"{response} ---> {language}") 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions