Answer to Question #274260 in Python for Happpy

Question #274260

Suppose there is a dictionary named exam_marks as given below.

exam_marks = {'Cierra Vega': 175, 'Alden Cantrell': 200, 'Kierra Gentry': 165, 'Pierre Cox': 190}

Write a Python program that takes an input from the user and creates a new dictionary with only those elements from 'exam_marks' whose keys have values higher than the user input (inclusive).

===================================================================

Sample Input 1:

170

Sample Output 1:

{'Cierra Vega': 175, 'Alden Cantrell': 200, 'Pierre Cox': 190}



1
Expert's answer
2021-12-01T18:36:14-0500
# the given dictionary
exam_marks = {'Cierra Vega': 175, 'Alden Cantrell': 200, 'Kierra Gentry': 165, 'Pierre Cox': 190}


number = int(input("Enter marks: "))            
dictionary = {}                                 
for key in exam_marks:                        
    if exam_marks[key] >= number:                 
        dictionary [key] = exam_marks[key]       


print("The dictionary is: ", dictionary )                  

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS