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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:08:17+00:00 2026-05-24T04:08:17+00:00

I decided to look a bit into python. I found this book began to

  • 0

I decided to look a bit into python. I found this book began to read it and did some exercises from it. Now I’m stuck at chapter 6, exactly here.
Sorry for my newbie question but where comes this test()-function from?

def mysum(xs):
    """ Sum all the numbers in the list xs, and return the total. """
    running_total = 0
    for x in xs:
        running_total = running_total + x
    return running_total

#add tests like these to your test suite ...
test(mysum([1, 2, 3, 4]), 10)
test(mysum([1.25, 2.5, 1.75]), 5.5)
test(mysum([1, -2, 3]), 2)
test(mysum([ ]), 0)
test(mysum(range(11)), 55)    # Remember that 11 is not in the list that range generates.

I can’t seem to find it and its never mentioned earlier in the book. I only found a module named test. Now I’m kind of confused, am I missing something? There is also a version of this book for Python 2.x which does not use this function in Chapter 6….
Please enlighten a newbie and sorry again for this weird question.

  • 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-05-24T04:08:17+00:00Added an answer on May 24, 2026 at 4:08 am

    Its in Section 6.7 of the linked chapter.

    def test(actual, expected):
        """ Compare the actual to the expected value,
            and print a suitable message.
        """
        import sys
        linenum = sys._getframe(1).f_lineno   # get the caller's line number.
        if (expected == actual):
            msg = "Test on line {0} passed.".format(linenum)
        else:
            msg = ("Test on line {0} failed. Expected '{1}', but got '{2}'."
                                         . format(linenum, expected, actual))
        print(msg)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've decided to look into Clojure (inspired by this book ). After a bit
I'm trying to maintain/update/rewrite/fix a bit of Python that looks a bit like this:
Hey, I'm trying to learn a bit about Python so I decided to follow
We decided to use the minimumRequiredVersion in our clickOnce application manifest, and now when
I was looking at some code I've inherited and I couldn't decided if I
I have to maintain some legacy codes,parts of it look like the following: /*
We decided to use mongodb for some web application (instead of mysql) but want
This should a quick question for some easy rep. I'm doing some PHP Website
I've decided to have a look around for open source projects that need a
So I decided to take a look at Smalltalk. Googling led me to Squeak

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.