Created
May 8, 2025 03:37
-
-
Save Analytics-89/dd873af601f890a4dd235052cbdd112e to your computer and use it in GitHub Desktop.
indented block error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.')