139,248 views
9 votes
9 votes
What am i doing wrong ????

def main():

firstNumber = float(input('Enter your first number'))
secondNumber = float(input('Enter your second number'))

return firstNumber, secondNumber

def add(firstNumber ,secondNumber):
return firstNumber + secondNumber
def subtract(firstNumber , secondNumber):
return firstNumber - secondNumber
def multipy (firstNumber , secondNumber):
return firstNumber * secondNumber
def divide (firstNumber, secondNumber):
return firstNumber / secondNumber
def modulo (firstNumber , secondNumber):
return firstNumber % secondNumber
def exponent (firstNumber , secondNumber):
return firstNumber ** secondNumber



def userOutput(firstNumber, secondNumber,total,sub,mul,div,mod,exp):
print(firstNumber + secondNumber == total)
print(firstNumber - secondNumber == Sub)
print (firstNumber * secondNumber == mul)
print (firstNumber / secondNumber == div)
print (firstNumber % secondNumber == mod)
print (firstNumber ** secondNumber == exp)

total = add(firstNumber , secondNumber)
sub = subtract(firstNumber, secondNumber)
mul = multiply(firstNumber, secondNumber)
div = divide(firstNumber, secondNumber)
mod = modulo(firstNumber, secondNumber)
exp = exponent(firstNumber, secondNumber)



def printAnswer (anwserAdd, anwserSubtract,anwserMultiply,anwserdivide, anwserModulo,anwserExponent):
print (anwserAdd, anwserSubtract,anwserMultiply,anwserdivide, anwserModulo,anwserExponent)


# --------------------------------
# I've called main() for you.
# This line is a special way to call main
# that allows me to test your code. Do not change it!
if __name__ == '__main__':
main()

User Khanna
by
3.1k points

2 Answers

23 votes
23 votes

Step-by-step explanation:

what is the problem ? does it not compile or run at all ? it do you get something unexpected ?

did you specify your whole program or just a part ?

based on what I see I would assume it does not compile and produce, so your cannot even start it.

and that should be because the way you defined printAnswer.

you did not specify types for the parameters, and because there is also no call of printAnswer, the compiler does not have any clue about the types that way either.

for userOutput this was different, because the return statements of all the functions (add, subtract, ...) provide the type information.

also, there is no end for the function printAnswer.

the compiler simply goes on after the print statement, assuming that the following still belongs to printAnswer and finds an if-starement checking a variable __name__, which might be unknown to the compiler (if there are no other definitions included at least in the background). and then a call of main.

and then finally printAnswer is finished.

further observations :

the print statements in userOutput clearly want to use strings, but you did not include any ' signs.

I think you meant them to look like

print(firstNumber, ' + ', secondNumber, ' == ', total)

our did you mean it as a user guideline for selecting or rather specifying an operation on the 2 numbers entered earlier ?

then it would be like

print('firstNumber + secondNumber == total')

then you never call printAnswer or userOutput anywhere. you don't ask for the user input anywhere to select the desired operation. and you don't check that input anywhere to define what operation to perform.

so, the main program will ask for the 2 numbers and then simply end.

User Zephni
by
2.5k points
21 votes
21 votes
You have a few problems.

You are not calling main() anywhere.
You are not calling userOutput() anywhere.
You are not calling printAnswer() anywhere
User JackCA
by
2.4k points