Computers and Technology

Exercise 2. The file exercise2.py contains code to create a dictionary where the keys are random integers and the values are random floating-point numbers. Add code to the file that allows the user to repeatedly enter a key value and test whether or not the key is in the dictionary. If the key is in the dictionary print the key-value pair. Format the floating-point value to display two decimal places. If the key is not in the dictionary print an appropriate message. Sample Behavior: Enter a key: 600 Key 600 is in the dictionary with value 69.67 Enter another pair (y/n)? y Enter a key: 900 Key 900 is not in the dictionary Enter another pair (y/n)? y Enter a key: 487 Key 487 is in the dictionary with value 70.61 Enter another pair (y/n)? n import random 8 9 10 # set the seed for the random number generator random. seed ( 121415) 11 # set a size for the dictionary numItems = 20 12 13 14 15 16 17 18 19 20 21 22 # key range keyUpperLimit = numItems * 100 23 # generate a dicionary dt of random values dt = {} for cnt in range (numItems) : key = random. randint(1, keyUpperLimit) # make sure we end up with numitem unique keys while key in dt: key = random. randint(1, keyUpperLimit) # add the item to the dictionary dt[key] = random. uniform(0,100) 24 25 26 27 28 29 30 31 32 33 34 35 36 # display the content of the dictionary print('Content of the dictionary') print(f'{"key":>10s}{"value":> ;10s}') - for k, v in dt. items(): print(f'{k:10d}{v:10.2f}') # insert your code below this comment 37

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 15:00, taylorsamodell3217
Who is the first president to use social media as part of his campaign strategy
Answers: 1
image
Computers and Technology, 24.06.2019 16:50, Laylahlettiere
Develop the program incrementally: a) start by reading and displaying each line of the input file to make sure you are reading the data set correctly. b) use the split string method to extract information from each line into a list. print the list to prove that this step is working correctly. d) convert the exam scores to type int and calculate the student’s average. display those items to prove this step is working correctly. e) create a tuple containing the six items for each student (name, exam scores, exam mean). display the tuples to prove this step is working correctly. (optionally, you may want to have the exam scores in a list so your tuple is (name, scores_list, f) append each tuple to a list. display the list to prove this step is working correctly. g) use the sort list method to re-order the tuples in the list. display the list to prove this step is working correctly. h) use a for statement to display the contents of the list as a table (with appropriate formatting). i) use a for statement to calculate the average of all scores on exam #1, then display the results. note that you could have calculated this average within the first loop, but we are explicitly requiring you to do this calculation by looping though your list of tuples. j) add the logic to calculate the average of all scores on exam #2, then display the results.
Answers: 2
image
Computers and Technology, 24.06.2019 17:00, harlon852
The length of time that a slide appears before automatically advancing to the next slide can be set in the timing group under the transitions tab. transition to this slide group under the transitions tab. timing group in the master slide view. transition to this slide group in the master slide view.
Answers: 1
image
Computers and Technology, 24.06.2019 21:30, croxy0514
Jenny wants to create an animated short video to add to her website. which software will she use to create this animated video?
Answers: 1
Do you know the correct answer?
Exercise 2. The file exercise2.py contains code to create a dictionary where the keys are random int...

Questions in other subjects:

Konu
Mathematics, 30.09.2019 09:20
Konu
Social Studies, 30.09.2019 09:20
Konu
Chemistry, 30.09.2019 09:20