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")
4 ответов
+ 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")
+ 3
#or like this:
https://code.sololearn.com/c964MlAE4dyJ/?ref=app
+ 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
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"))