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 8745965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:07:15+00:00 2026-06-13T12:07:15+00:00

I have started working with the google Python class but I am getting some

  • 0

I have started working with the google Python class but I am getting some odd results and a full day of debugging hasn’t help me resolve it.

What seems to be happening is that the functions are returning None instead of the values I am assigning them, but why this is happening is eluding me. I wrote in some debug lines and tried to step through it but I am seeing what is causing the behaviour.

Here is a sample of some of the debug output:

C:\Users\toshiba\Dropbox\DEV\python\google-python-exercises\basic>python string2.py
front_back
  X  got: None expected: 'abxcdy'
 OK  got: 'abcxydez' expected: 'abcxydez'
 OK  got: 'KitDontenut' expected: 'KitDontenut'

The code is from googles class and then the functions written by me.

# F. front_back
# Consider dividing a string into two halves.
# If the length is even, the front and back halves are the same length.
# If the length is odd, we'll say that the extra char goes in the front half.
# e.g. 'abcde', the front half is 'abc', the back half 'de'.
# Given 2 strings, a and b, return a string of the form
#  a-front + b-front + a-back + b-back
def front_back(a, b):
  # +++your code here+++

  # Debug hardcode setting
  # set to 1 to debug (default 0 off)
  letsDebug = 0

  alpha, bravo = a, b
  if letsDebug == 1:
        endString = a \
        + ' ' \
        + b
        return endString

  lenA = len(alpha)
  lenB = len(bravo)

  if lenA % 2 == 1:
    statAlpha = 'odd'
  else:
    statAlpha = 'even'

  if lenB % 2 == 1:
    statBravo = 'odd'
  else:
    statBravo = 'even'
  if letsDebug == 2:
        endString = a \
        + ' ' \
        + b \
        + ' ' \
        + statAlpha \
        +  ' ' \
        + statBravo 
        return endString

  workB = lenB / 2
  workA = lenA / 2
  if letsDebug == 3:
        endString = a \
        + ' ' \
        + b \
        + ' ' \
        + statAlpha \
        +  ' ' \
        + statBravo \
        + ' ' \
        + str(workA) \
        + ' ' \
        + str(workB) 
        return endString

  if statAlpha == 'even':
    aFront, aBack = alpha[:workA], alpha[-workA:]
  else:
    aFront, aBack = alpha[:(workA+1)], alpha[-workA:]

  if statBravo == 'even':
    bFront, bBack = bravo[:workB], bravo[-workB:]
  else:
    bFront, bBack = bravo[:(workB+1)], bravo[-workB:]

    if letsDebug == 4:
        endString = a \
        + ' ' \
        + str(workA) \
        + ' ' \
        + b \
        + ' ' \
        + str(workB) \
        + ' ' \
        + statAlpha \
        +  ' ' \
        + statBravo \
        + ' ' \
        + aFront \
        + ' ' \
        + bFront \
        + ' ' \
        + aBack \
        + ' ' \
        + bBack \
        + ' ' \
        + aFront + bFront + aBack + bBack
    else:
        endString = aFront + bFront + aBack + bBack

    return endString


# Simple provided test() function used in main() to print
# what each function returns vs. what it's supposed to return.
def test(got, expected):
  if got == expected:
    prefix = ' OK '
  else:
    prefix = '  X '
  print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected))


# main() calls the above functions with interesting inputs,
# using the above test() to check if the result is correct or not.
def main():
  print 'verbing'
  test(verbing('hail'), 'hailing')
  test(verbing('swiming'), 'swimingly')
  test(verbing('do'), 'do')

  print
  print 'not_bad'
  test(not_bad('This movie is not so bad'), 'This movie is good')
  test(not_bad('This dinner is not that bad!'), 'This dinner is good!')
  test(not_bad('This tea is not hot'), 'This tea is not hot')
  test(not_bad("It's bad yet not"), "It's bad yet not")

  print
  print 'front_back'
  test(front_back('abcd', 'xy'), 'abxcdy')
  test(front_back('abcde', 'xyz'), 'abcxydez')
  test(front_back('Kitten', 'Donut'), 'KitDontenut')

if __name__ == '__main__':
  main()

Many thanks to any who can decipher where I have gone ary here.

  • 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-13T12:07:15+00:00Added an answer on June 13, 2026 at 12:07 pm

    It looks like the whole block at the end of front_back is indented one too many levels. From if letsDebug == 4: to return endString – this is all part of the else block started above it (the else for the statement if statBravo == 'even':). I’m guessing this is supposed to be at function scope instead.

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

Sidebar

Related Questions

I have started working on some algorithm problems when I saw a problem asking
I have started working on a simple XML pull-parser, and as I've just defuzzed
I have started working on a project which requires Natural Language Processing. We have
I have started working with enhanced for loops due to it's best practices and
We have started working on VS11 projects involving a DDD - Agile - TDD
I have started working on yii framework and I am following the yii blog
I am working on ubuntu OS,I have started working on pentaho-BI using eclipse.. Just
I am a newbie to Ruby on Rails . I have started working on
This is a very elementary I realize, I have recently started working with asp.net
I have just started leaning and working on xquery with java. I have a

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.