+ 2
Need help with for loops
The question is Fill in the blanks to iterate over the list using a for loop and print its values Here's what I have so far: list = [1,2,3] for var in list: print ( ) (I need to fill in the blank brackets above, but I am not sure what to put there).
4 Antworten
+ 5
list=[1,2,3]
for var in list:
print(var)
use indentation after for loop.
another idea:
print(var,end=' ')
+ 1
Loop is basically a repeated form of a task... If you want to input on 🔳 something many times you should use loop by giving range according to your need... And for printing, do the same but apply output bject or function....
0
the line "for var in list" translates to: for every var(variable) in the list. in the code, you refer to each object in the list as "var". soo if you want to display all of the objects in the list, you type:"for var in list: print (var)". sorry if i didn't explain well enough.
0
list=[1,2,3]
for var in list:
print(var) # Todo lo que se quiera ejecutar dentro del loop debe ir indentado. Imprime los valores de la lista en líneas separadas, a medida que va leyendo la lista.
print(var,end=' '). #Imprime los valores seguidos en la misma línea.
print(f"Los valores son {Var}")
Espero haber ayudado.