Given a dictionary where the keys are names and the values are ages, write a program that takes a name as input and prints the corresponding age if the name exists in the dictionary, otherwise it prints 'Not found'.
Dictionary methods
Find age by name in a dictionary
Report a typo
Sample Input 1:
Alice
{'Alice': 25, 'Bob': 30, 'Charlie': 35}Sample Output 1:
25Sample Input 2:
David
{'Alice': 25, 'Bob': 30, 'Charlie': 35}Sample Output 2:
Not foundWrite a program in Python 3
def get_age(name, ages):
# Write your code here
name = input()
ages = eval(input())
print(get_age(name, ages))
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.