0
Can someone explain this code to me?
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: This is the only solution I used that would work: contacts = [ ('James', 42), ('Amy', 24), ('John', 31), ('Amanda', 63), ('Bob', 18) ] contacts1 = dict(contacts) a = input(" ") print(f"{a} is {contacts1[a]}") What is contacts1 doing? Why is input including " "? someone please explain the entire print line, what's the f for?
1 Resposta
+ 2
the f"" denotes a formatted string.
see the {a} right after? in formatted strings, anything in these braces: {} can be a variable of any type. And when printed, prints the string version of the variables value.