Can you tell me why “my created code” gives a syntax error unless I comment out the previous called functions. I assume it’s holding some values that must be reset.
#function to add two numbers
def add(a, b):
print(f"ADDING {a} + {b}")
return a + b
#function to subtract two numbers
def subtract(a, b):
print(f"SUBTRACTING {a} - {b}")
return a - b
#function to multiply two numbers
def multiply(a, b):
print(f"MULTIPLYING {a} * {b}")
return a * b
#function to divide two numbers
def divide(a, b):
print(f"DIVIDING {a} / {b}")
return a / b
#print string
print("Let's do some math with just functions!")
#Call each function using two parameters and assigning to a different variables
"""
age = add(30, 5)
height = subtract(78, 4)
weight = multiply(90, 2)
iq = divide(100, 2)
#print string and the contents of the appropriate variable
print(f"Age: {age}, Height: {height}, Weight: {weight}, IQ: {iq}")
#A puzzle for the extra credit, type it in anyway.
print("Here is a puzzle.")
#start with inner most parenthesis plugging in the contents from each variable
#performing operations and assigning to variable
what = add(age, subtract(height, multiply(weight, divide(iq, 2))))
#print strings and variable contents in between
print("That becomes: ", what, "Can you do it by hand?"
"""
#This part of code gives syntax error unless previously called function is commented out
#my created problem - (25/5) x 2 -1 + 3 = 12
answer = add(3 , subtract(multiply(2 ,divide(25, 5)), 1))
print("\n")
print(f"Here is my problem: {answer} \n")