NovFora Dev

python code not working :( help!!

Elizabeth Robinson

Elizabeth Robinson

2 months ago

hi everyone i am trying to make a simple script that prints hello world but keep getting an indentation error and dont understand what it means or how to fix it please anyone knows python im so lost and need this for my assignment due tomorrow thnx

Reese Cruz

Reese Cruz

2 months ago

Try checking your indentation — that's usually it with python errors.

Stella Cook

Stella Cook

2 months ago

You didn't attach the error or the code, but here are the top 5 reasons Python scripts fail for beginners:

  1. IndentationError: Python uses spaces/tabs to define blocks (if statements, loops, functions). Mix tabs and spaces in the same file and it breaks silently until you run it. Check your editor's whitespace settings.

  2. Mutable Default Arguments: def add_item(items=[]) looks harmless but all calls share that SAME list instance. If you append to it once, every future call starts with those items already in the list. Use None instead: def add_item(items=None): items = items or [].

  3. NameError: You're trying to use a variable before defining it, or inside a scope where it hasn't been created. Check your nesting carefully — variables defined inside an if-block aren't always accessible outside of it.

Join the conversation to leave a reply.

Sign in to reply

Related topics