in Education by
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)

1 Answer

0 votes
by
Edited code, should work: 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: ")) w7 = Week7(numOne, numTwo) 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(w7.addNum()) elif which_Function == 2: print(w7.multNum()) elif which_Function == 3: print(w7.divNum()) elif which_Function == 4: print(w7.subtNum()) elif which_Function == 5: print(w7.allNum()) elif which_Function == 6: exit() Explanation of changes: w7 = Week7(numOne, numTwo) create an instance of the Week7 object print(w7.addNum()) call the function and print the output. --ditto--mult----- etc. I also changed the order because it did not relate to what was displayed.

Related questions

0 votes
    I'm creating my first program on python. The objective is to get an output of trip cost. In the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I'm trying to do the Udacity mini project and I've got the latest version of the SKLearn library ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I'm testing such sentence to extract entity values: s = "Height: 3m, width: 4.0m, others: 3.4 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    >>> a=[1,2,3] >>> a.remove(2) >>> a [1, 3] >>> a=[1,2,3] >>> del a[1] >>> a ... above three methods to remove an element from a list? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I am trying to fit some (numpy) data into python skLearn modules, but keep getting error messages. When ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I have multiple xlsx files with data in it that i want to import to separate dataframes in Python. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Convert pandas DateTimeIndex to Unix Time? (7 answers) Closed 3 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    Let's say I have the following code: from types import coroutine @coroutine def stop(): yield 1 async ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I have multiple xlsx files with data in it that i want to import to separate dataframes in Python. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I used the function for gower distance from this link: https://sourceforge.net/projects/gower-distance- ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have two Dataframes : DF1(That i've just resampled): Mi_pollution.head(): Sensor_ID Time_Instant ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    I want to have root mean squared of gradient boosting algorithm but when I want to print it, I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I want to have root mean squared of gradient boosting algorithm but when I want to print it, I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I want to get the values of col1 in 3 different columns with separate headers. Date/Time col1 0 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I'm working on a project which need these deep learning libraries - keras and tensorflow. Unfortunately, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
...