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

  • SEARCH
  • Home
  • 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 8598647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:12:14+00:00 2026-06-12T01:12:14+00:00

I am doing the python tutorial by Google right now, and am completing the

  • 0

I am doing the python tutorial by Google right now, and am completing the file list1.py.

I am supposed to fill in the def match_ends(words) part with my own code, which is supposed to count how many words in the input words have both: more than 2 letters and the same beginning and ending letters.

When I run the code I wrote using python 2.7, it works fine. But when I run it using 3.2, it doesn’t. Further, when I type the line that it says has a problem into IDLE 3.2, the troublesome line runs fine.

This is list1.py:

def match_ends(words):
  count = 0
  for x in words:
    if len(x) >= 2 and x[0] == x[len(x)-1]:
        count += 1
  return count
def test(got, expected):
  if got == expected:
    prefix = ' OK '
  else:
    prefix = '  X '
  print('%s got: %s expected: %s' % (prefix, repr(got), repr(expected)))
def main():
  print('match_ends')
  test(match_ends(['aba', 'xyz', 'aa', 'x', 'bbb']), 3)
  test(match_ends(['', 'x', 'xy', 'xyx', 'xx']), 2)
  test(match_ends(['aaa', 'be', 'abc', 'hello']), 1)
if __name__ == '__main__':
  main()

When I run it in command line for Python 2.7, it works fine, outputs:

 OK  got: 3 expected: 3
 OK  got: 2 expected: 2
 OK  got: 1 expected: 1

When I run it in command line for Python 3.2, it doesn’t work, outputs:

  File "D:\Projects\Programming\Python\Tutorials\Google Python Class\google-python-exercises\basic\list1.py", line 26
    if len(x) >= 2 and x[0] == x[len(x)-1]:
                                          ^
TabError: inconsistent use of tabs and spaces in indentation

Finally, when I use IDLE 3.2, I get:

>>> def match_ends(words):
    count = 0
    for x in words:
        if len(x) >= 2 and x[0] == x[len(x)-1]:
            count += 1
    return count

>>> match_ends(["heh", "pork", "veal", "sodas"])
2

I’m extremely new to Python, most of the errors that are generated have taken some time to figure out, but I’ve been stuck on this one for awhile. I can’t figure it out. Why won’t it work in Python 3.2, and only when I do the command-line version? How do I fix this?

  • 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-12T01:12:15+00:00Added an answer on June 12, 2026 at 1:12 am

    You’re probably mixing tabs and spaces characters, which is not allowed anymore in Python 3.x.
    You can fix this by displaying whitespaces characters within your text editor.

    Indentation is rejected as inconsistent if a source file mixes tabs and spaces in a way that makes the meaning dependent on the worth of a tab in spaces; a TabError is raised in that case.

    Quoted from: http://docs.python.org/py3k/reference/lexical_analysis.html#indentation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Learning django & python. Just set up a new site after doing the tutorial.
I am currently doing a python tutorial, but they use IDLE, and I opted
I am new to Python, trying to learn it by doing a tutorial based
I have written the odd handy function while I've been doing python. (A few
Python is doing string multiplication where I would expect it to do numeric multiplication,
What is the best way of doing this in Python? for (v = n
im doing some basic socket programming in python. But im having some trouble figuring
I'm doing a project in Python (3.2) for which I need to compare user
I've been doing testing work in Python using QtWebkit/Spynner. As QtWebKit has Javascript support
I found some old Python code that was doing something like: if type(var) is

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.