Helpe me!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Helpe me!!

Hi people! I am doing a Python practice using Tuples. 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, find the name in the contact list and get its age in the format presented below: Example entry: "John". Output example: John is 31 This is the final algorithm I have made. contacts = [     ('James', 42),     ('Amy', 24),     ('John', 31),     ('Amanda', 63),     ('Bob', 18) ] name = input() found = False  for i in contacts:    if(name == i[0]):       print(name, " is",  i[1])       found = True        break  if(not found ):    print("Not Found") Everything seems to be in order, but when I run the tests I get errors in some test cases. The funny thing is that the error messages report:  Entry: Amanda Your result: Amanda is 63 Expected result: Amanda is 63 Any idea?

27th Sep 2023, 10:15 PM
Javier
Javier - avatar
3 Answers
+ 7
Javier the print statement outputs a space between arguments that are separated by a comma. The middle string, " is", has a leading space. That causes two spaces to be printed between name and the word "is".
27th Sep 2023, 10:36 PM
Brian
Brian - avatar
+ 3
Thanks bud!, problem solved.
27th Sep 2023, 11:10 PM
Javier
Javier - avatar
+ 3
YW
27th Sep 2023, 11:12 PM
Brian
Brian - avatar