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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:13:22+00:00 2026-05-13T13:13:22+00:00

I have two classes: class Dog(object): def __init__(self, name): self.name = name class Toy(object):

  • 0

I have two classes:

class Dog(object):
    def __init__(self, name):
        self.name = name
class Toy(object):
    def play(self):
        print "Squeak!"

I need to come up with a method called play(self, toy, n) for class Dog. It prints “Yip! ” (with a space) followed by the output from toy.play on the same line. This happens n times, with the n outputs on separate lines. If n is negative, it is the same as if it were 0.

What I did is

def play(self, toy, n):
    count = 1
    if n > 0:
        while count <= n:
            print "Yip! %s " % Toy().play()
            count += 1
    else:
        print None

However, when I call Dog(‘big’).play(toy, 3) or whatever n is, it shows that
Squeak!
Yip! None
Squeak!
Yip! None
Squeak!
Yip! None
I don’t know what’s wrong. Squeal! and Yip! should suppose to be at the same line while there are at separate now and there order should be opposite. And why there is a None?
Can anyone please help me out?

  • 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-13T13:13:22+00:00Added an answer on May 13, 2026 at 1:13 pm

    In your example call, Dog('big').play(0), you are not passing the toy argument — that’s what it’s complaining about! Pass a toy argument before n and that will be better.

    Then you can start addressing the bugs in your play implementation: why are you making a new toy rather than use the argument, why are you printing 'None' when that’s not part of the specs, how you’re uselessly printing the return value of the Toy.play method (which returns None, implicitly) rather than working along with the fact that the latter method is printing something, and never incrementing count and so ending up in infinite loops.
    (four serious bugs in eight lines plus one in the call just has to be some sort of a record, I believe;-).

    BTW, homework is normally tagged with the tag homework, not exercise. (And, there’s a further bug in your Q’s title, as no classmethod is actually around, just a good old plain and perfectly normal instance method).

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

Sidebar

Ask A Question

Stats

  • Questions 383k
  • Answers 383k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Went with Google Checkout, just wanted to close this question. May 14, 2026 at 10:42 pm
  • Editorial Team
    Editorial Team added an answer An alternative to consider is to target the VS2005 C++… May 14, 2026 at 10:42 pm
  • Editorial Team
    Editorial Team added an answer You need to construct your query as follows: "select count(*)… May 14, 2026 at 10:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.