Bottom Page

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
buran wrote Dec-07-2017, 02:12 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#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
>>>
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Newbie needs help with a simple program feynarun 3 77 Jan-15-2020, 01:17 PM
Last Post: DeaD_EyE
  Python Program to Make a Simple Calculator jack_sparrow007 2 5,227 Oct-19-2018, 08:32 AM
Last Post: volcano63
  a 'simple' program, hard as .... to understand meems 3 2,098 Dec-04-2016, 10:59 PM
Last Post: meems

Forum Jump:


Users browsing this thread: 1 Guest(s)