PYTHON CODE:
# declaring 'grade' dictionary with the given keys, values
grade={'Monday':1,'Tuesday':2,'Wednesday':3,'Thursday':4,'Friday':5}
# adding 'Saturday' key and value '6'
grade['Saturday']=6
# printing the dictionary after adding the key, value
print('After appending the key, value to the dictionary:
',grade)
SCREENSHOT FOR CODING:
SCREENSHOT FOR OUTPUT:
3 Dn Ent Write a python program to create a Dictionary named grade with the given...
Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for the dictionary are strings and the values are lists of numbers. The function should create a new dictionary where the keys are the same strings as the original dictionary and the values are tuples. The first entry in each tuple should be the weighted average of the non-negative values in the list (where the weight was the number in the 0 position of the...
Python Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following: How to format each dictionary item as a text string in the input file. How to covert each input string into a dictionary item. How to format each item of your inverted dictionary as a text string in the output file. Create an input file with your original...
Paperweight using Python 3 Create a dictionary named weight, initialised with the following values: "pencil": 10 "pen": 20 "paper": 4 "eraser": 80 Create another dictionary named available, initialised with the following values: "pen": 3 "pencil": 5 "eraser": 2 "paper": 10 If the weight dictionary gives the weight of an individual item of each type, and the available dictionary specifies the number of each item that is available, write code that determines the total weight of all available items (i.e. what...
Python 3 Write a function named starCounter that takes three parameters: 1. a dictionary named starDictionary. Each key in starDictionary is the name of a star (a string). Its value is a dictionary with two keys: the string 'distance' and the string 'type'. The value associated with key 'distance' is the distance from our solar system in light years. The value associated with key 'type' is a classification such as 'supergiant' or 'dwarf'. 2. a number, maxDistance 3. a string,...
PYTHON CODE First Code: Write a program that uses a text file to store the daysand hours that a user worked in a week. The program should begin by prompting for the number of days worked in the week. It should continue with a loop for input of the days and hours and for writing these to the file, each on its own line. Sample Output (inputs shown in boldface) How many days did you work this week? 5 Enter...
Python 3 Write a function named inverse that takes a single parameter, a dictionary. In this dictionary each key is a student, represented by a string. The value of each key is a list of courses, each represented by a string, in which the student is enrolled. The function inverse should compute and return a dictionary in which each key is a course and the associated value is a list of students enrolled in that course. For example, the following...
(Create a binary data file) Write a program to create a file named CreateBinaryFile.dat if it does not exist. Append new data to it if it already exists. Write 50 integers created randomly into the file using binary I/O.
Storing data and adding to data in a dictionary: Experiment with Python dictionaries and their keys() member function that returns a list of a dictionary's keys. You can check if a particular key is in a dictionary by using the in test with the keys list. For example, if our dictionary is MyDict = { 1: 'One', 2: 'Two', 3: 'Three' } Then ( 2 in MyDict.keys() ) evaluates to True, indicating that 2 is a valid key for MyDict....
Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following:How to format each dictionary item as a text string in the input file.How to covert each input string into a dictionary item.How to format each item of your inverted dictionary as a text string in the output file.Create an input file with your original three-or-more items and add at...