Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    6
    ReputationRep:
    Offline

    21
    ReputationRep:
    All of your functions and if-statements have the same problem, so I'll amend one function and one if statement for you so you can do the rest.

    def add(numOne, numTwo):
    sumOutput = (numOne) (numTwo)
    print (sumOutput)

    if operator == "add":
    add(numOne, numTwo)

    That should solve it. Notice the quotation marks and added parameters to the function definition.

    edit: May I suggest using something like Pastebin to share code next time? It'll keep the tabs/spacing (especially important in Python) which helps to make code easier to read and allows others to spot any tab/spacing errors!
    Offline

    16
    ReputationRep:
    You need to initialise you variables (numOne and numTwo) before you initialise your functions.

    Also your syntax is weird. When you call a function, you write it like this:

    divide()

    You are also putting brackets around the counditions for your if statements and when you call variables. Don't do this.
    This aint C++

    For example you written this: sumOutput = (numOne) + (numTwo)
    You should write it like this: sumOutput = numOne + numTwo

    And you written this: if operator == (subtract):
    When you hsould have written this: if operator == "subtract":

    Notice the speechmarks. Since operator is going to be a string, then subtract should be designated as a string.
    • Thread Starter
    Offline

    6
    ReputationRep:
    thanks for the help. The problem still isn't fixed. Nothing get outputted
    Offline

    21
    ReputationRep:
    (Original post by Spazum)
    thanks for the help. The problem still isn't fixed. Nothing get outputted
    Can you post your entire code into Pastebin and paste the exact error message (if there is one) onto here?
    • Thread Starter
    Offline

    6
    ReputationRep:
    Name:  Screenshot (63).png
Views: 17
Size:  29.5 KB
    Offline

    13
    ReputationRep:
    (Original post by Spazum)
    Name:  Screenshot (63).png
Views: 17
Size:  29.5 KB
    try removing that space after each 'print statement (so you should have 'print(x)', etc), tell us what happens.
    • Thread Starter
    Offline

    6
    ReputationRep:
    (Original post by Killer Bean)
    try removing that space after each 'print statement (so you should have 'print(x)', etc), tell us what happens.
    that doesn't make a difference
    Offline

    10
    ReputationRep:
    what line does it have an error at? I would suggest using return instead of print when defining your functions; this should be a more efficient use of code. When outputting your answer, what you have written just tells the computer to use the function, however you have not said in each if statement what variables you are using the function on.
    I'll try for the first if statement and you can replicate this in your other statements to see if it works.

    if operator == ("add");
    print(add(numOne,numTwo)

    try this and see if it helps
    Offline

    0
    ReputationRep:
    (Original post by Spazum)
    Name:  Screenshot (63).png
Views: 17
Size:  29.5 KB
    You don't need the brackets around add, subtract, etc. for the bottom half. Also you need to call the function by putting brackets at the end of the function name and enter the variables that will be needed.

    eg.
    if operator == "add":
    add(numOne, numTwo)
    • Thread Starter
    Offline

    6
    ReputationRep:
    there is no error. It just outputs nothing
    Offline

    13
    ReputationRep:
    (Original post by Spazum)
    that doesn't make a difference
    Okay, I'm guessing your problem is not that you have an error, but that the code just isn't doing what you want it to do, which is what happened in my IDE.

    I've just got this to work in my own IDE. It works when you use the 'raw_input' function instead of 'input'; but I've got to be honest, I'm not sure why.

    I changed a couple of other things though, so try that on your end and let me know if it works.

    EDIT: If it helps, here's what I changed:

    Script:

    Attachment 702620
    • Thread Starter
    Offline

    6
    ReputationRep:
    (Original post by TJ149)
    what line does it have an error at? I would suggest using return instead of print when defining your functions; this should be a more efficient use of code. When outputting your answer, what you have written just tells the computer to use the function, however you have not said in each if statement what variables you are using the function on.
    I'll try for the first if statement and you can replicate this in your other statements to see if it works.

    if operator == ("add";
    print(add(numOne,numTwo)

    try this and see if it helps
    I still down't get an output
    Offline

    7
    ReputationRep:
    Change your 'if' statements - you are not calling the function.

    if operator == "add":
    add(numOne, numTwo)

    Do these for all the if statements.
    • Thread Starter
    Offline

    6
    ReputationRep:
    (Original post by Kartheyan)
    Change your 'if' statements - you are not calling the function.

    if operator == "add":
    add(numOne, numTwo)

    Do these for all the if statements.
    I've tried that and i still don't get an output
    Offline

    7
    ReputationRep:
    (Original post by Spazum)
    I've tried that and i still don't get an output
    Send me a screenshot of the corrected code, with the edits I told you to make.
    Offline

    6
    ReputationRep:
    (Original post by Spazum)
    Anyone now why this isn't working? Im sure you can work out what i am trying to do


    def add():
    sumOutput = (numOne) + (numTwo)
    print (sumOutput)

    def subtract():
    sumOutput = (numOne) - (numTwo)
    print (sumOutput)

    def divide():
    sumOutput = (numOne) / (numTwo)
    print (sumOutput)

    def multiply():
    sumOutput = (numOne) * (numTwo)
    print (sumOutput)

    numOne = int(input("Enter first number: ")
    numTwo = int(input("Enter second number: ")
    operator = input("Do you want to add, subtract, divide or multiply? "

    if operator == (add):
    (add)

    if operator == (subtract):
    (subtract)

    if operator == (divide):
    (divide)

    if operator == (multiply):
    (multiply)
    If you're trying to make a calculator use the following code:

    #Output message to user explaining the calculator print("This is a simple calculator you can use to make calculations."
    #Ask user to enter first number print("Enter a number"
    #User input first number
    var_number1 =int(input())
    #Ask user to enter second number
    print("Enter another number"
    #User input second number
    var_number2 =int(input())
    #Ask user what operation to use
    print("Which calculation do you want to do? Enter + , - , * , /"
    #User input calculation
    var_userchoice = input()
    #Add first number by second number and store in a variable
    var_sum = var_number1 + var_number2
    #Subtract first number by second number and store in a variable
    var_subtract = var_number1 - var_number2
    #Multiply first number by second number and store in a variable
    var_multiply = var_number1 * var_number2
    #Divide first number by second number and store in a variable
    var_divide = var_number1 / var_number2
    #Use the correct operation
    if var_userchoice == '+':
    print("The answer is",var_sum)
    elif var_userchoice == '-':
    print("The answer is",var_subtract)
    elif var_userchoice == '*':
    print("The answer is",var_multiply)
    else: print("The answer is",var_divide)

    I'm sure there's a better way to do it but this is what I have and it works
    • Thread Starter
    Offline

    6
    ReputationRep:
    Name:  Screenshot (64).png
Views: 15
Size:  78.8 KB
    (Original post by Kartheyan)
    Send me a screenshot of the corrected code, with the edits I told you to make.
    Just done it for the add function so far
    Offline

    10
    ReputationRep:
    This was my code i suggest taking certain parts of it and making the few changes.
    Attached Images
     
    Offline

    7
    ReputationRep:
    (Original post by Spazum)
    Name:  Screenshot (64).png
Views: 15
Size:  78.8 KB

    Just done it for the add function so far
    Remove the print statement in the if statement so just add(numOne, numTwo), as you are already calling print in your function.
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Did TEF Bronze Award affect your UCAS choices?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.