(Python) - I am having trouble with a code of mine...
Okay so here is the thing, We are suppose to make a code, that passes our data from one function to the other. I took a picture of my professors example, and tried mimicking it. However, I am getting an error when I try passing the information.
Here is what I did, and the error i got. My Code: def main(): print("Options: ") print("1. Addition") print("2. Subtraction") print("3. Multiplication") print("4. Division") print("""[Type "Stop" at any time to stop]""") exitChoice = input("Please choose from the following options: ") choice = int(exitChoice) if (exitChoice == "Stop"): print("Okay, goodbye! ") if (choice == 1): addition() elif (choice == 2): subtraction() elif (choice == 3): multiplication() elif (choice == 4): division() def addition(): firstNum = float(input("Please enter the first number: ")) secondNum = float(input("Please enter the second number: ")) additionSum = (firstNum + secondNum) print("After addition, your sum is %.2f" %additionSum) print("""[If you wish to continue to Step 2 - Subtraction, type "Continue"]""") choose = input("Please enter your decision: ") if (choose == "Stop" or choose == "stop"): print("Okay, goodbye! ") if (choose == "Continue" or choose == "continue"): subtraction(additionSum) def subtraction(): firstNum = float(input("Please enter the first number: ")) secondNum = float(input("Please enter the second number: ")) product = (firstNum - secondNum) print("After Subtraction, your product is %.2f" %product) main()
@518nad
can u give me ur question in detail
are u there
u are inputting something into subtraction when it doesnt take input
What do you mean it doesn't take input? The Subtraction function does have input D:
-.-
subtraction()
Sorry we barely learned functions yesterday, I am pretty new to it still. Let me get back to you tomorrow, about the instructions, I am a little confused myself now...
xD
just do the change i saidq
But if you look at the picture I sent, of my professors code, She had subtraction(total)
i dont know her subtraction function but this means she was allowing some inut, like her add also allows choice variabe
The number and type of arguments that a function is called with MUST match the function's definition. In your case, additiion() is calling subtraction() with one argument, and subtraction is defined to be called with zero arguments. You'd need to change the definition of subtraction to something like: def subtraction( additionSum ):
Join our real-time social learning platform and learn together with your friends!