0

tuples at python3

anyone can helpme to find name and grade at elementary school print (x + " in" + grade) python3 code: colony = [ ('Namy', 5), ('Red', 7), ('Franky', 7), ('Dary', 4), ('Melky', 3) ] x = str(input()) if x in colony: print(x + " in" + grade ) else: print("Not found")

12th Jul 2021, 9:28 AM
Choi_142
Choi_142 - avatar
4 Answers
+ 7
#or do it like this colony = [ ('Namy', 5), ('Red', 7), ('Franky', 7), ('Dary', 4), ('Melky', 3) ] x = str(input()) for name,grade in colony: if name == x: print(x +" in " +str(grade)) break else: print("Not found")
12th Jul 2021, 9:50 AM
Simba
Simba - avatar
12th Jul 2021, 9:58 AM
Shadoff
Shadoff - avatar
+ 2
What does the variable, "contacts" refer to? Also, since they are tuples in a list (containers in a container) try a nested loop to look for input and then you can print the match out
12th Jul 2021, 9:36 AM
Slick
Slick - avatar
0
# shorter: colony = [ ('Namy', 5), ('Red', 7), ('Franky', 7), ('Dary', 4), ('Melky', 3) ] x = input() print(next((f"{n} in {g}" for n, g in colony if n==x), "Not found"))
12th Jul 2021, 5:10 PM
visph
visph - avatar