Write a function that accepts two parameters: a dictionary and a number, and prints
only the keys that have values more than the passed number.
Answers
Program in Python:
def fun(dic, n):
print("Keys are : ")
for key, value in dic.items():
if value > n:
print(key)
keys = []
values = []
n = int(input("Enter number of elements : "))
print("Enter all the keys :")
for i in range(0, n):
ele = int(input())
keys.append(ele)
print("Enter all the values :")
for i in range(0, n):
ele = int(input())
values.append(ele)
dic = {}
for k in keys:
for v in values:
dic[k] = v
values.remove(v)
break
print("Dictionary : ",dic)
num = int(input("Enter a number : "))
fun(dic, num)
Output:
Enter number of elements : 5
Enter all the keys :
1
2
3
4
5
Enter all the values :
10
20
30
40
50
Dictionary : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50}
Enter a number : 30
Keys are :
4
5