Need a little help 4.2 practice | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Need a little help 4.2 practice

I am not doing something right using Tuples, any help would be greatly appreciated. This is for 4.2 practice bonus question. Here is the bonus question explanation ------------------------------ You are given a list of contacts, where each contact is represented by a tuple, with the name and age of the contact. Complete the program to get a string as input, search for the name in the list of contacts and output the age of the contact in the format presented below: Sample Input: John Sample Output: John is 31 +----------------here is my code below---------++--------------- name = input() contacts = { 'James': 42, 'Amy':24, 'John': 31, 'Amanda': 63, 'Bob': 18, } print (name +"is" +contacts[1])

8th May 2021, 6:21 AM
k2hawk 10
k2hawk 10 - avatar
2 Answers
+ 3
k2hawk 10 , try -> print(name + " is " + str(contacts[name])).
8th May 2021, 7:16 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
8th May 2021, 7:22 AM
k2hawk 10
k2hawk 10 - avatar