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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:40:55+00:00 2026-05-21T08:40:55+00:00

I am learning OOP with python .trying with small console application Stock class Stock(object):

  • 0

I am learning OOP with python .trying with small console application Stock

class Stock(object):

    def __init__(self, stockName, stockLimit, inStock, rentPrice):

        self.stockName  = stockName   # private
        self.stockLimit = stockLimit  # private
        self.inStock    = inStock     # private
        self.rentPrice  = rentPrice   # private

    def inputStock(self, nProduct):

        if(nProduct >= (self.stockLimit - self.inStock)):
            self.inStock = self.stockLimit
        else:
            self.inStock += nProduct 

    def invoice(self, nDay):
        return self.rentPrice * nDay


class StockProduct(Stock):

    def __init__(self, factor):
        # the base-class constructor:
        Stock.__init__(self, stockName, stockLimit, inStock, rentPrice)
        self.factor = factor # Extra for this stock

    def invoice(self, nDay):
        return Stock.invoice(self, nDay) * self.factor

class StockMaterial(Stock):

    def __init__(self,factor):
        # the base-class constructor:
        Stock.__init__(self, stockName, stockLimit, inStock, rentPrice)
        self.factor = factor # Extra for this stock

    def invoice(self,nDay):
        return Stock.invoice(self, nDay)*self.factor

if __name__ == "__main__":

    N = nDay = 0
    myStock = Stock("stock111", 500, 200, 400000)
    N = float(raw_input("How many product into stock: "+str(myStock.stockName)+" ? "))
    myStock.inputStock(N)
    nDay = int(raw_input("How many days for rent : "+str(myStock.stockName)+" ? "))
    print "Invoice for rent the stock: "+str(myStock.stockName)+ " = "+ str(myStock.invoice(nDay))

    StockProduct = StockProduct("stock222",800, 250, 450000, 0.9)

    N = float(raw_input("How many product into stock: "+str(StockProduct.stockName)+" ? "))
    StockProduct.inputStock(N)
    nDay = int(raw_input("How many days for rent : "+str(StockProduct.stockName)+" ? "))
    print "Invoice for rent the stock: "+str(StockProduct.stockName)+ " = "+ str(StockProduct.invoice(nDay))

I have two questions:

  1. with my method invoice, how Can I do method overloading in python ?
  2. I added some attribute in the child I got the following error message:

    StockProduct = StockProduct("stock222",800, 250, 450000, 0.9)
    TypeError
    
    error: __init__() takes exactly 2 arguments (6 given)
    

What I should do here?

Anybody can help me please?

Thank in advance

  • 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-21T08:40:55+00:00Added an answer on May 21, 2026 at 8:40 am
    1. The overloaded invoice in the derived class should work fine.

    2. Your base class constructor needs to have all the parameters, so :

      class StockProduct(Stock):
          def __init__(self, stockName, stockLimit, inStock, rentPrice, factor):
              # the base-class constructor:
              Stock.__init__(self, stockName, stockLimit, inStock, rentPrice)
              self.factor = factor
      
          def invoice(self, nDay):
              return Stock.invoice(self, nDay) * self.factor
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning OOP with python. I want to implement something like to display:
I'm learning c++ and OOP and I have class called Pion and I have
I'm learning more about javascript OOP by rolling my own console.log variant with some
I am learning OOP's PHP by reading the php offical documents first: class SimpleClass
I'm learning PHP OOP and Im trying to understand why the following script doesn't
I am learning OOP with PHP. I am creating a class to extract XML
Ok I am trying to start really learning OOP style in PHP. I have
I'm self-learning C#, OOP, and WPF so the potential for stuff ups is staggering.
I am taking my first OOP class (learning Java) in the fall so I've
I started learning OOP applied to C++. Now I want to know if I

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.