This is my first attempt at creating and using a class. The error is occurring when I ask the user for input. I'm getting the following error:
n1 = Arithmetic.float_input("Enter your First number: ")
TypeError: float_input() missing 1 required positional argument: 'msg'
Here is my code.
# Define class
class Arithmetic:
def float_input(self, msg): # Use this function for exception handling during user input
while True:
try:
return float(input(msg))
except ValueError:
print("You must enter a number!")
else:
break
def add(self, n1, n2):
sum1 = n1 + n2
print(n1,"+" ,n2,"=", sum1)
def sub(self, n1, n2):
diff = n1 - n2
print(n1,"-",n2,"-", diff)
def mult(self, n1, n2):
product = n1 * n2
print(n1,"*",n2, "=", product)
def div(self, n1, n2):
if n2 == 0:
print(n1, "/",n2,"= You cannot divide by Zero")
else:
quotient = n1 / n2
print(n1, "/",n2,"=", quotient)
def allInOne(self, n1, n2):
#Store values in dictionary (not required, just excercising dictionary skill)
res = {"add": add(n1, n2), "sub": sub(n1, n2), "mult": mult(n1, n2), "div": div(n1, n2)}
# Declare variables. Ask user for input and use the exception handling function
n1 = Arithmetic.float_input("Enter your First number: ")
n2 = Arithmetic.float_input("Enter your Second number: ")
What am I missing?