Ask your own question, for FREE!
Computer Science 13 Online
OpenStudy (itz_sid):

(Python) - I am having trouble with a code of mine...

OpenStudy (itz_sid):

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.

OpenStudy (itz_sid):

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()

OpenStudy (itz_sid):

@518nad

OpenStudy (518nad):

can u give me ur question in detail

OpenStudy (518nad):

are u there

OpenStudy (518nad):

u are inputting something into subtraction when it doesnt take input

OpenStudy (itz_sid):

What do you mean it doesn't take input? The Subtraction function does have input D:

OpenStudy (518nad):

-.-

OpenStudy (518nad):

subtraction()

OpenStudy (itz_sid):

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...

OpenStudy (518nad):

xD

OpenStudy (518nad):

just do the change i saidq

OpenStudy (itz_sid):

But if you look at the picture I sent, of my professors code, She had subtraction(total)

OpenStudy (518nad):

i dont know her subtraction function but this means she was allowing some inut, like her add also allows choice variabe

OpenStudy (rsmith6559):

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 ):

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!