1

I want the below program to accept input for a,b,c and d using raw_input.Please modify the below program to accept inputs for a,b,c and d.I tried doing this

def add(a, b)
    print "Enter the values of a and b"
    a = int(raw_input())
    b = int(raw_input())
    print return a + b

The trace back is

File "a.py", line 5
return a + b)
     ^
SyntaxError: invalid syntax

I did this and I got syntax error.I did similarly for all the other functions.

def add(a, b):
    print "ADDING %d + %d" %(a, b)
    return a + b

def subtract(a, b):
    print "subtract %d - %d" %(a, b)
    return a - b

def multiply(a, b):
    print "multiply %d * %d" %(a, b)
    return a * b

def divide(a, b):
    print "divide %d + %d" %(a, b)
    return a / b

print "Let's do some math with just functions!"

age = add(30, 5)
height = subtract(78, 5)
weight = multiply(90, 2)
iq = divide(100, 2)

print "Age: %d, Height: %d, Weight: %d, IQ: %d" % (age, height, weight, iq)

print "Here is a puzzle"

what = add(age, subtract(height, multiply(weight, divide(iq, 2))))

print "That is:", what, "How about that?"           
7
  • Should I add my code in the comments here? Commented Jun 15, 2013 at 22:42
  • You can edit your question to add more detail. Commented Jun 15, 2013 at 22:53
  • 1
    I have added the code above. Commented Jun 15, 2013 at 22:56
  • 1
    What was the exact traceback of the error you got? Commented Jun 15, 2013 at 23:00
  • File "a.py", line 5 return a + b) ^ SyntaxError: invalid syntax Commented Jun 15, 2013 at 23:07

2 Answers 2

2

The problem is in your add function.

print return a + b

should be

return a + b
Sign up to request clarification or add additional context in comments.

Comments

0
from sys import argv
def add(a,b):
    print "Addition %d+%d" %(a,b)
    return a+b

a=int(raw_input())
b=int(raw_input())
#c=add(a,b)
#print "Addition Is %d" %c
print "Addition Is %d" %add(a,b)

try it for enter value through raw_input()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.