Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with simple program
#1
hi

can you please help i dont understand why im getting the error:

C:\Users\juanb>python
Python 3.7.0a2 (v3.7.0a2:f7ac4fe, Oct 17 2017, 16:23:57) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> bag=[33,44,6,76,7,88,96,79]
>>> len(bag)
8
>>> for item in bag:
... print(item)
Error:
File "<stdin>", line 2 print(item) ^ IndentationError: expected an indented block >>>
THANKS A LOT !!

JUAN
Reply
#2
at the moment line 7 is at the same level of indentation as line 6. you need to indent the body of the loop

>>> bag=[33,44,6,76,7,88,96,79]
>>> for item in bag:
...     print(item)
...
33
44
6
76
7
88
96
79
>>>
Reply
#3
Hi, Python error messages are usually pretty clear and give good hints, as is the case in your situation.
Code inside for block (and other blocks for that matter) needs to be indented one level, meaning you need to add 4 spaces before print.
This can be hard to notice if you write directly into an interpreter. I recommend writing code in a text editor and running it as a Python script.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Suggestions for a simple data analysis program t4keheart 0 1,748 Mar-08-2021, 03:45 PM
Last Post: t4keheart
  logging in simple program Inkanus 1 1,665 Dec-18-2020, 02:36 PM
Last Post: snippsat
  Newbie needs help with a simple program feynarun 3 2,194 Jan-15-2020, 01:17 PM
Last Post: DeaD_EyE
  Python Program to Make a Simple Calculator jack_sparrow007 2 10,061 Oct-19-2018, 08:32 AM
Last Post: volcano63
  a 'simple' program, hard as .... to understand meems 3 5,080 Dec-04-2016, 10:59 PM
Last Post: meems

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020