def_func.py 597 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import math
  4. def my_abs(x):
  5. if not isinstance(x, (int, float)):
  6. raise TypeError('bad operand type')
  7. if x >= 0:
  8. return x
  9. else:
  10. return -x
  11. def move(x, y, step, angle=0):
  12. nx = x + step * math.cos(angle)
  13. ny = y - step * math.sin(angle)
  14. return nx, ny
  15. n = my_abs(-20)
  16. print(n)
  17. x, y = move(100, 100, 60, math.pi / 6)
  18. print(x, y)
  19. # TypeError: bad operand type:
  20. # my_abs('123')
  21. def addSum(x,y):
  22. sum = x + y ;
  23. return sum;
  24. # 多个返回值就过个返回和接收
  25. count = addSum(1,2);
  26. print(count);