Python Forum

Full Version: this small code dosento work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys

im just learinig python so the task is to pass throu list a and print only numbers that are bigger than 5. my code isnt working and i dont know whats wrong;

here is the code

a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
for i in a:
if i < 5:
print(i)

the error msg i get:

File "C:/Users/juanb/PycharmProjects/test/tes1.py", line 3
if i < 5:
^

IndentationError: expected an indented block

Process finished with exit code 1


thanks a lot !
juan
Indentation is part of python syntax, so:
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
for i in a:
    if i < 5:
        print(i)
Also this does the opposite of what you asked:
Output:
1 1 2 3
is this what you wanted?
>>> a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
>>> for i in a:
...     if i < 5:
...         print(a[i])
...
1
1
2
3
>>>