Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8534203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:08:24+00:00 2026-06-11T10:08:24+00:00

I am Python newbie and I am working on NLP using Python. I am

  • 0

I am Python newbie and I am working on NLP using Python. I am having an error in writing an if-else block in Python. When I am writing only an if block at that time it is working fine:

if xyzzy.endswith('l'):
    print xyzzy

After entering a colon (:) I am pressing Enter and it is automatically taking me to the correct indentation.

But when I am trying to add an else block to it after pressing the Enter key after the print statement, it is considering it to be statement of an IF block only, so it is giving me incorrect indentation as I want an else block after, while when I am trying to write else block my self it is giving me this error.

else:
   ^

IndentationError: unexpected indent

What should I do after writing print statement? Enter is clearly not working, because it is taking the cursor forward, while when I use space to come to the correct pointer it is giving me an error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:08:25+00:00Added an answer on June 11, 2026 at 10:08 am

    It’s hard to see from your post what the problem is, but an if-else is formatted like so

     if someCondition:
         do_something       # could be a single statement, or a series of statements
     else:
         do_something_else  # could be a single statement, or a series of statements
    

    I.e., the else needs to be at the same level as the corresponding if.

    See this Python doc/tutorial on if, and this other tutorial too.

    Sometimes when your editor does autoindent for you and you edit manually too things might get messed up, so you’ll have to figure out how your editor handles indentations (e.g., is it always using tabs or spaces?, what happens if you hit return etc).

    Also, be wary of mixing tabs and spaces, that will cause problems too (hard to spot since both are "invisible")

    With your updated post:

       if xyzzy.endswith('l'):
           print xyzzy
       else:
           something_else
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a newbie to Python, and mainly having a background of writing scripts for
python newbie here. I'm writing the code to control an experiment that has multiple
I am a newbie to Python, i am having some doubts on working of
Python newbie here. I'm writing an SMTP server using Twisted and twisted.mail.smtp. I'd like
I'm a newbie in boost.python and i'm getting this error that I would like
Python newbie at time of writing. This came up because I want a user
Python newbie here. I'm writing a script that can dump some output to either
Python newbie here: I'm writing a market simulation in Python using Pysage, and want
I am a Python and Qt newbie... I am working on a GUI program
I'm a python newbie and starting out with using the Bottle web framework on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.