Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 how do i fix this problem - IndentationError?
#1
I have never does any type of coding before and wanted to give it a try. I am using the book called python hunting. they told me to type this codes first so that I can load up pygame and eventually start developing games.


import pygame, sys
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((640,480))
while 1:
    for event in pygame.event.get():
	    if event.type == pygame.QUIT:
		    sys.exit()
	screen.fill((255,255,255))
    pygame.draw.circle(screen,(0,255,0),(100,100),20)
    pygame.display.update()
But whenever I try to open this file on python itself common Prompt(CMD) keeps telling me

line 9
screen.fill((255,255,255))

IndentationError: unindent does not match any outer indentation level

what does this mean???? how do I correct this???? Can someone please help. I have been trying to creak my head on this for more than 1 month now. A help will be really appreciated. Thankyou.
Larz60+ wrote Mar-12-2019, 09:01 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Fixed for you this time. Please use BBCode tage on all future posts. Thank you.
Quote
#2
That's because sys.exit requites an argument,
change line 8 to:
            sys.exit(0)
FYI: On future posts, when displaying errors, please show entire unmodified error traceback, enclosed in error tags.
Quote
#3
even after changing line 8 to sys.exit(0) it still shows this for line 9 when try to open it on Common Prompt

IndentationError: unindent does not match any outer indentation level
Quote
#4
(Mar-12-2019, 09:08 AM)GrandMaster101 Wrote: IndentationError: unindent does not match any outer indentation level

Are you sure you are not mixing tabs and spaces in your indentation white space? That will usually cause that error.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Life of Brian: Conjugate the verb, "to go" !
Quote
#5
I only used spacebar. I never used tab. The book I am using says not to use tab when writing the code.
Quote
#6
Please ---it's important to show error message verbatim, don't assume it's not all needed.
Quote
#7
so what do I do now to fix the problem???
Quote
#8
I copied your code to Jupyter Lab and ran it. It didn't raise any error. It opened pygame window with bright-green ball in upper left area which I assume is expected result.

I saved code into .py file and ran it under ipython. Same result. I ran it in terminal. Same result.

One possibility to debug is to copy code from this site back to your machine and check whether error is still there.

As side note - flake8 reported 13 problems with your code.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Life of Brian: Conjugate the verb, "to go" !
Quote
#9
Hi,

Same error on the following code:

import serial #seria lib
import numpy #numpy lib
import matplotlib.pyplot as plt #matplot lib
from drawnow import *

arduinoData = serial.Serial('com20', 9600)


while True: #loops forever
     while (arduinoData.inWaiting()==0): #Wait for data
        pass #does nothing
    arduinoString = arduinoData.readline()
    print (arduinoString)
Please help.
I tried adding an argument to arduinoData.readline(0)
same error on same line.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  IndentationError: expected an indented block ryder5227 2 174 Sep-27-2019, 06:59 PM
Last Post: jefsummers
  IndentationError on installed package evvvonder 3 475 Jun-29-2019, 10:30 PM
Last Post: Gribouillis
  Indentationerror Jack_Sparrow 4 1,107 May-16-2018, 05:50 PM
Last Post: Jack_Sparrow
  IndentationError message could be confusing to new programmers insearchofanswers87 1 511 May-16-2018, 05:05 PM
Last Post: Larz60+
  IndentationError: unexpected indent (Python) segs 8 7,362 Aug-11-2017, 03:13 PM
Last Post: segs

Forum Jump:


Users browsing this thread: 1 Guest(s)