0

How can I make this code easier? GPT helps me with this code, but I don’t understand what means Found and function For In. Inoob

contacts = [ ('James', 42), ('Amy', 24), ('John', 31), ('Amanda', 63), ('Bob', 18) ] key = input() found = False for name, age in contacts: if name == key: print (name, "is", age) found = True break if not found: print ("Not Found")

20th Sep 2023, 5:53 PM
Kanat
Kanat - avatar
10 ответов
+ 3
Without knowing the original task I would solve this with a dictionary, because this is much easier and shorter than using a for-loop. My approach you can see in the attached file: https://code.sololearn.com/c9weukqgI9MA/?ref=app
21st Sep 2023, 6:07 AM
Jan Markus
+ 7
What is the task description for this code you search for?
20th Sep 2023, 6:13 PM
JaScript
JaScript - avatar
+ 5
a bit late, but for the sake of completeness i have picked thd task description: the task is an exercise from `python developer`, `collection types`, `practice tuples`. task description: 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, 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 If the contact is not found, the program should output "Not Found".
21st Sep 2023, 6:35 PM
Lothar
Lothar - avatar
+ 4
jyonnyKumarHTMLCoditer , please do not spam in a post with a code that has no relation to the original topic.
24th Sep 2023, 7:21 PM
Lothar
Lothar - avatar
+ 4
Fidu King , please do not spam here. your post has no relation to the topic, and the code seems to be copied from someone else
26th Sep 2023, 1:28 PM
Lothar
Lothar - avatar
+ 3
The code has an array containing names and ages stored as tuples in the array, it takes a key from the user and declares a boolean called found to False and uses a for loop to check if the name entered by the user is in the array, if it is found it prints the name and corresponding age and found to True and breaks out of the loop. If at the end of the loop the key is not found then the program prints Not found
20th Sep 2023, 6:09 PM
Aweneg Rooney
Aweneg Rooney - avatar
+ 1
Thank you, you helped me
21st Sep 2023, 6:15 AM
Kanat
Kanat - avatar
0
Looks like a drop down list lookuo code … for selecting a name from a drop down (or other type of) list and then using the referenced data in something else .
22nd Sep 2023, 3:15 PM
Rob
0
Just a simple name / age lookup
22nd Sep 2023, 3:16 PM
Rob
0
No
28th Sep 2023, 6:34 AM
Fidu King
Fidu King - avatar