廖雪峰网站:学习python函数—定义函数(二)

def my_abs(x):
    if x >= 0:
        return x
    else:
        return -x

print(my_abs(-99))

# 空函数
def nop():
    pass

# 参数检查
def my_abs(x):
    if not isinstance(x, (int, float)):
        raise TypeError("bab operand type")
    if x >= 0:
        return x
    else:
        return -x



# 返回多个值

import math

def move(x, y, step, angle= 0):
    nx = x + step * math.cos(angle)
    ny = y - step * math.sin(angle)
    return nx, ny

n = my_abs(-20)
print(n)

x, y = move(100, 100, 60, math.pi/6)
print(x, y)

 

posted @ 2018-07-24 20:43  笑笑未来  阅读(221)  评论(0编辑  收藏  举报