Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Analytics-89/dd873af601f890a4dd235052cbdd112e to your computer and use it in GitHub Desktop.
Save Analytics-89/dd873af601f890a4dd235052cbdd112e to your computer and use it in GitHub Desktop.
indented block error
Hi Iam getting error for the below code in Mu editor .. can anyone help me here to understand the reason
name ='marry'
password == 'swordfish'
if name == 'marry':
print('Hello,marry')
if password == 'swordfish':
print('Access granted.')
else:
print('wrong password.')
Error: File "c:\users\barnana dutta\smart parking\python_programe_files\while_loop.py", line 5
print('Hello,marry')
^
IndentationError: expected an indented block
>>>
@RENA2
Copy link

RENA2 commented Jul 5, 2025

The error in your code is due to incorrect indentation and an extra = in the password check. Here’s the corrected version:

Issues in your code:
password == 'swordfish' → You used == (comparison) instead of = (assignment).

Incorrect else indentation → In Python, else must align with its corresponding if.

Missing indentation for the first print → Code inside an if block must be indented.

Here is the corrected code

name = 'marry'
password = 'swordfish' # Use "=" for assignment, not "=="

if name == 'marry':
print('Hello, marry') # Indent this line

if password == 'swordfish': # Now "==" is correct for comparison
print('Access granted.')
else: # Align with the "if" statement
print('Wrong password.')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment