i'm suppose to write a program with two classes, the first class takes two numbers and adds them together. the second class has no methods but has an object called add2.

this is what i got


class Adder1 (object):
number1 = int(input("Give me a number:"))
number2 = int(input("Give me another number:"))
def add(self, sum):
self.sum = number1 + number2
return sum

class Adder2 (object, add2):
#add2 don't know what to do with it?

Print (add2.add(number1, number2))

First of all, you don't have to do int(input()) because input() returns a number anyway.

And you should start with better explaining the rest of the problem

First of all, you don't have to do int(input()) because input() returns a number anyway.

And you should start with better explaining the rest of the problem

I think he's using python 3... That being said, we don't give homework help to those that don't show effort.

Also, to the OP please use code tags when posting code on this forum. IT makes it easier to answer your questions.

Member Avatar for leegeorg07

This untested code so dont trust it completely.

class maths:
    def __init__(self, n1, n2):
        self.n1 = n1
        self.n2 = n2
    def change(self, n1, n2):
        self.n1 = n1
        self.n2 = n2
        print('I have changed %i and %i.' % (self.n1, self.n2)
    def add(self):
        print(self.n1+self.n2)
    def minus(self):
        print(self.n1-self.n2)

this can be extended to do other things like divide and others
a current example would be:

test = maths(1, 2)
test.add() #will return:
3
test.change(5, 3) #will return:
I have changed 5 and 3
test.minus() #will return:
2

btw I only guessed these based on my knowledge.
I hope this helps

So input() in python 3 returns a string?

So input() in python 3 returns a string?

Yes, that's what a quick look in the manual will tell you.

So input() in python 3 returns a string?

Yes, and / returns a float.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.