Problem Description
Write a program to check whether the given key is present in the dictionary.
If the key is present then display the value of the entered key and if the key is not present then display the appropriate message
Input:
1.Get two dictionaries key-value elements
2. Get the key value to be searched
Output:
1. Display the first dictionary
2. Display the second dictionary
3. Display the concatenated dictionary
4. Display whether the key is present or nor and the respective value of the key.
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to outputCODING ARENA
a=int(input())
b=int(input())
c=int(input())
d=int(input())
key=int(input())
d1={}
d2={}
d1.update({a:b})
d2.update({c:d})
print("First Dictionary")
print(d1)
print("Second Dictionary")
print(d2)
d1.update(d2)
print("Concatenated dictionary is")
print(d1)
if key in d1.keys():
print("Key is present and value of the key is")
print(d1[key])
else:
print("Key not present")
Test Case 1
Input (stdin)81 9 64 8 81
Expected OutputFirst Dictionary {81: 9} Second Dictionary {64: 8} Concatenated dictionary is {81: 9, 64: 8} Key is present and value of the key is 9
Test Case 2
Input (stdin)100 10 144 12 10
Expected OutputFirst Dictionary {100: 10} Second Dictionary {144: 12} Concatenated dictionary is {100: 10, 144: 12} Key not present
No comments:
Post a Comment