+ 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