学习python第n天——我在看笨办法学python

代码

def add(a, b):
    print(f"ADDING {a} + {b}")
    return a + b

def subtract(a, b):
    print(f"SUBTRACTING {a} - {b}")
    return a - b

def muitiply(a, b):
    print(f"MUITIPLY {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 = muitiply(90, 2)
iq = divide(100, 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, muitiply(weight,divide(iq,2))))

print ("That becomes:", what, "Can you do it by hand?")

 

运行结果

PS C:\Users\HH\lpthw> python ex13.py
Let's do some math with just functions!
ADDING 30 + 5
SUBTRACTING 78 - 4
MUITIPLY 90 - 2
DIVIDING 100 / 2
Age: 35, Height: 74, weight: 180, Iq :50.0
Here is a puzzle.
DIVIDING 50.0 / 2
MUITIPLY 180 - 25.0
SUBTRACTING 74 - 4500.0
ADDING 35 + -4426.0
That becomes: -4391.0 Can you do it by hand?
PS C:\Users\HH\lpthw>

 

posted on 2022-01-06 20:05  何奈时  阅读(29)  评论(0)    收藏  举报

导航