subject

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

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 04:30, Lilabbychichi
Ryan is working on the layout of her web page. she needs to figure out where her header, navigation bar, text, and images should go. what technique can her?
Answers: 1
image
Computers and Technology, 22.06.2019 18:30, Angelanova69134
Technician a says that a shop towel should never be used to clean around the flange area before replacing an automatic transmission filter. technician b says that a dimpled transmission fluid pan can be repaired. who is right
Answers: 3
image
Computers and Technology, 23.06.2019 01:50, rhonda45801
Free points just awnser this. what should i watch on netflix
Answers: 2
image
Computers and Technology, 23.06.2019 05:20, jaylenmiller437
Which operating system is a version of linux?
Answers: 1
You know the right answer?
Exercise 2. The file exercise2.py contains code to create a dictionary where the keys are random int...

Questions in other subjects: