I am working on a homework assignment in which we are creating a class to be used in a program to be used to do basic math computations either individually or all of the computations at once. So add, subtract, multiply, divide or all four.
I think that the most of the code is good but I cannot get it to print after the user has put their numbers in and selected a somputation method. I have tried print(Week7.addNum), print(Week7.addNum()), print(Week7.addnum(numOne, numTwo)). I get various errors or nothing. With the print(Week7.addnum) I get. I have only been working on the add function and figured if I could get that to work the rest follow suit.
class Week7:
def __init__(self, numOne, numTwo):
self.numOne = numOne
self.numTwo = numTwo
def addNum(self):
return (self.numOne + self.numTwo)
def subtNum(self):
return (self.numOne - self.numTwo)
def multNum(self):
return (self.numOne * self.numTwo)
def divNum(self):
if self.numTwo !=0:
return (self.numOne / self.numTwo)
else:
return print('You can not divde by 0')
def allNum(self):
return (self.numOne + self.numTwo, self.numOne - self.numTwo, self.numOne * self.numTwo, self.numOne / self.numTwo )
numOne=int(input("Enter first number: "))
numTwo=int(input("Enter second number: "))
functions = [ "1) Add two numbers",
"2) Mult two numbers",
"3) Divide two numbers",
"4) Subtract two numbers",
"5) All in one: Perform all math Operations",
"6) End Program"
]
for x in functions:
print( x )
print()
which_Function = int(input("Please select what operation you would like to perform: ") )
if which_Function == 1:
print(Week7.addNum)
elif which_Function == 2:
Week7.subtNum(self)
elif which_Function == 3:
Week7.multNum(self)
elif which_Function == 4:
Week7.divNum(self)
elif which_Function == 5:
Week7.allNum(self)
elif which_Function == 6:
exit
I think everything works except for the actual printing of the problem. I want to get "1 + 2 = 3" as an example. I know I need to put the "+" and "=" in the print out but I can figure out where once I get it to print at all. Thanks in advance. Dave
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)