I need to design a calculator with the following UI:
Welcome to Calculator!
1 Addition
2 Subtraction
3 Multiplication
4 Division
Which operation are you going to use?: 1
How many numbers are you going to use?: 2
Please enter the number: 3
Please enter the number: 1
The answer is 4.
This is what I have so far:
print("Welcome to Calculator!")
class Calculator:
def addition(self,x,y):
added = x + y
return sum
def subtraction(self,x,y):
diff = x - y
return diff
def multiplication(self,x,y):
prod = x * y
return prod
def division(self,x,y):
quo = x / y
return quo
calculator = Calculator()
print("1 \tAddition")
print("2 \tSubtraction")
print("3 \tMultiplication")
print("4 \tDivision")
operations = int(input("What operation would you like to use?: "))
x = int(input("How many numbers would you like to use?: "))
if operations == 1:
a = 0
sum = 0
while a < x:
number = int(input("Please enter number here: "))
a += 1
sum = calculator.addition(number,sum)
I seriously need some help! All the tutorials on calculators in Python 3 are far more simple than this (as in it only take 2 numbers and then simply prints out the answer).
I need help getting the functions in the Calculator class I made to work. When I try running what I have so far, it lets me input my numbers and whatnot, but then it just ends. It doesn't run the operation or whatever. I am aware I only have addition so far, but if someone can just help me figure out addition, I think I can do the rest.