笨办法学python3练习代码ex21.py
def add(a, b):
print(f"ADDING {a} + {b}")
return (a + b)
def subtract(a, b): #subtract :减去的意思
print(f"SUBTRACT {a} - {b}")
return a - b
def multiply(a, b):
print(f"MULTIPLY {a } * {b}")
return a * b
def divide(a, b):
print(f"DIVIDE {a} / {b}")
return a / b
print("Let‘s do some math with just function!")
age = add(30, 5)
height = subtract(78, 4)
weight = multiply(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, multiply(weight, divide(iq, 2))))
print("That becomes: ",what, "Can you do it by hand? ")注意在运行该代码时刚开始出现过一次错误:IndentationError: unindent does not match any outer indentation level。百度这条错误原因发现是因为定义函数的时候缩进有问题。但是我的缩进看上去没有问题。如何查看缩进是不是有问题?
在notepad++里面查看缩进:菜单中视图-->显示符号-->显示空格与制表符选项打钩。在查看时注意把notepad++界面最好调成白色比较好。方法:设置菜单->语言格式设置->选择主题(default即可)。