Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
List
How do you search through a list? Example: look if the value of 25 exists in the list: Listc = [40,30,50,25]
22 Respostas
0
No. Change value in my code, which i posted last,.. And see output.
Else part belong to for loop. Not to if block. Lenoname
+ 11
# Hi! You use āinā:
print(25 in Listc)
+ 4
Use "in" keyword
+ 2
n = 30 # Is 30 in list?
mylist = [10, 20, 40, 30, 50]
for val in mylist:
if val == n:
print(n, "found in list!")
break
else:
print(n, "not found in list.")
+ 1
Can i do it with a loop?
+ 1
Jayakrishnaš®š³ Because the chapter iām at still hasnāt introduced āinā yet.
+ 1
Yes, I already, updated on that doubt.
See code again..
change input and try again code.
+ 1
Jayakrishnaš®š³ like this?i changed b on purpose, gives no output
b = 70
a = [5,7,8,4,9]
for i in a:
if i == b:
print("Score")
break
print("0 points")
+ 1
listc=[40,30,50,25]
Print(listc[3])
+ 1
if any(list(map(lambda x: True if x==25 else False, Listc))):
print(True )
0
Yes.
You can Try..
But if if done in a single line, then why need loop!!!
0
Then go for loop.
Internally ' in ' does the same, I think.
0
Jayakrishnaš®š³ almost zero idea how
0
Lenoname You have now code already..,
Learn more by completing lessons.. There you can find details with examples...
0
Per Bratthammar I just want the āscoreā to be printed out, not the rest.
b = 4
a = [5,7,8,4,9]
for i in a:
if i == b:
print("Score")
break
else:
print("0 points")
0
Says
0 point
0 point
0 point
Score
0
Jayakrishnaš®š³ and if it doesnt find 25 in the list?(lets say its not there) i want it to say ā0 pointā
0
Hola