Discuss / Python / 再简单的代码也要亲手打一遍

再简单的代码也要亲手打一遍

Topic source

翁岚敏

#1 Created at ... [Delete] [Delete and Lock User]

练习

-- coding:utf-8 --

import math

def quadratic(a,b,c): d = bb-4ac if d > 0: return (-b+math.sqrt(d))/(2a),(-b-math.sqrt(d))/(2a) elif d == 0: return (-b+math.sqrt(d))/(2a) else: return

测试

print(quadratic(2,3,1)) print(quadratic(1,3,-4))

def_func.py

!/usr/bn/env python3

-- coding:utf-8 --

import math

def my_abs(x): if not isinstance(x, (int, float)): raise TypeError('bad operand type') if x >=0: return x else: return -x

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)


  • 1

Reply