def add(a, b):
print(f"Adding {a} + {b}")
return a + b
def subtract(a, b):
print(f"Substracting {a} - {b}")
return a - b
def multiply(a, b):
print(f"Multiplying {a} * {b}")
return a * b
def divide(a, b):
print(f"Dividing {a} / {b}")
return a / b
print("Let's do some math with just functions!")
age=add(30,5)
height=subtract(78,4)
weight=multiply(90,2)
iq=divide(1000,2)
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.")
what=add(age, subtract(height,multiply(weight, divide(iq, 2))))
print("that becomes: ", what, "can you do it by hand?")
结果为:
*
用户输入浮点数float(intput())
*
python函数在最后的公式中是由内向外执行的,因此打印也是由内向外