Click here to Skip to main content
15,902,636 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Following code is down below , i want anyone to check is it right and solve my problem in spyder.

What I have tried:

class Nse():
    def __init__(self, name, value):
        self.name = name
        self.value = value
        def output(self):
            print("Your stock name is "+ self.name + "Your stock value is" + self.value)
            j = Nse('TATA','34')
            m = Nse('EDUCOMP','1')
            j.output()
            m.output()
Posted
Updated 19-May-20 2:47am
Comments
Richard Deeming 19-May-20 8:37am    
Nobody can solve your problem because you haven't described what the problem is.

Click the green "Improve question" link and update your question with a complete description of the problem. Include the full details of any errors. Explain what output you're getting that you think you shouldn't, or what output you're not getting that you think you should.

Remember, we can't see your screen, access your computer, or read you mind. The only information we have to work with is what you provide in your question.

1 solution

No, it's wrong. Your indentation for the output method makes it part of the constructor. Also you are creating objects of the class inside one of its methods (output). And you should use commas in print calls to separate fields rather than plus.
It should be something like:
Python
class Nse():
    def __init__(self, name, value):
        self.name = name
        self.value = value

    def output(self): # this method is separate from the constructor
        print("Your stock name is", self.name, "Your stock value is", self.value)

# these lines are not part of the Nse class.
j = Nse('TATA','34')
m = Nse('EDUCOMP','1')
j.output()
m.output()
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900