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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:53:42+00:00 2026-05-22T22:53:42+00:00

I made a simple code to demonstrate and understand classes – however when I

  • 0

I made a simple code to demonstrate and understand classes – however when I run this, my lists show that they are empty, containing “None” values instead of the strings that the user enters as names.

#Static methods do not require the object to be initiated. Can be remotely accessed from outside the function .

#Counting critters and remote access.

class Orc (object):

    total = 0       

    def get_score (self):
        print "The number of orcs the orc factory has made is",Orc.total   

    def __init__ (self):
        Orc.total += 1
        name =  raw_input ("I am a critter by the name of:\n")


#Creating 10 Orcs 


list = []

for i in range (4):    list[i] = list.append(Orc.get_score(Orc()))  

print "You have created 4 Orcs!" print "The name of your first orc is",list[0] print "The name of your fourth orc is", list[3]
  • 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-22T22:53:43+00:00Added an answer on May 22, 2026 at 10:53 pm

    There are a few errors in your code. First in the way you use lists. Second, in the way you call methods on your objects. The combination of errors explains why you have a list of None at the end.

    List name

    list = []
    

    Don’t name a list list. It is already the name of, well…, the list class, i.e. in Python you can do my_list = [] or my_list = list() with the exact same effect.

    You want to call your list something meaningful, like orc_list

    List Insertion

    for i in range (4):
        orc_list[i] = orc_list.append(...)
    

    orc_list.append does what it says: it appends an element to the given list. However, it does not return anything. So what your code is doing is

    1. taking an empty list
    2. setting i to 0
    3. inserting what you pass to append at the end of the list
    4. inserting None at index i and thus overriding what you did in 3.
    5. incrementing i
    6. going back to 3.

    You want to simply use orc_list.append(...)

    Method Call

    Orc.get_score(Orc())
    

    I imagine you are getting confused by the self argument. In a class, Python will automatically pass the instance you are working on as the self argument. You don’t need to provide that argument.

    You want to write

    Orc().get_score()
    

    This creates an Orc object, and then calls get_score on it. Python ‘injects’ the Orc instance you have created into get_score for you.

    Method Return

    We’re now down to

    orc_list.append(Orc().get_score())
    

    which is equivalent to

    score = Orc().get_score()
    orc_list.append(score)
    

    The problem is that there is no return statement in get_score. This means that python will return None when you call that method. Which means that you are appending None to your list.

    You want to have

    def get_score(self):
        print "The number of orcs the orc factory has made is", Orc.total
        return Orc.total
    

    Static behaviour

    If you really wanted to have a method not bound to an instance of the Orc class, you could use either a class method or a static method.

    In your case, you do not need to do anything to the class object, so your choice would be to use a static method.

    You would declare

    @staticmethod
    def get_score():
        print "The number of orcs the orc factory has made is", Orc.total
    

    You would then call that method using Orc.get_score()

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

Sidebar

Related Questions

I'm using this simple code: http://ejohn.org/blog/simple-javascript-inheritance/ Using this library, I made this simple class:
I have this simple code that records appends a log to a text file:
I have some relatively simple code I have made that is supposed to retrieve
I made a small and simple code that moves a div layer 200 pixles
I have a simple software that is made in Delphi 7, and it crashes
Today we faced a quite simple problem that were made even simpler by the
I had no luck with this question so I've produced this simple-as-possible-test-case to demonstrate
Hey all, i have made a simple form that mimiks the jQuery GROWL effect
I made a simple web service which worked nice with few systems that it
I've made a simple Android music player. I want to have a TextView that

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.