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

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 15:30
Hey so i was just trying out some game hacks so i took a paste from online and built it in my visual studio and then suddenly my computer was working or clicking on stuff on its own am i hacked?
Answers: 1
question
Computers and Technology, 23.06.2019 17:00
What are the 12 colors of the spectrum called?
Answers: 1
question
Computers and Technology, 24.06.2019 19:00
Luis is cloud-based( microsoft bot framework). true false
Answers: 1
question
Computers and Technology, 25.06.2019 01:30
Why is the most liked picture on instagram an eggy? owo
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
question
History, 25.04.2020 23:10
question
Mathematics, 25.04.2020 23:11
Questions on the website: 13722367