-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·58 lines (53 loc) · 1.22 KB
/
test.py
File metadata and controls
executable file
·58 lines (53 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/env python3
#-*- coding:utf8 -*-
def my_abs(x):
if not isinstance(x, (int,float)):
raise TypeError('bad 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
#-------------------------------
def quad(a,b,c):
if not isinstance(a,b,c, (int,float)):
raise TypeError('bad operand type')
if b**2-4*a*c <0:
print("not result")
else:
x1 = (math.sqrt(b**2 - 4*a*c) - b) / (2*a)
x2 = (-math.sqrt(b**2 - 4*a*c) - b)/ (2*a)
return x1,x2
#-----------------------------------
#default argument
def power(x,n=2):
s=1
while n>0:
n=n-1
s=s*x
return s
#print(power(3,3))
def roll(name,gender,age=20,city='BeiJing'):
print('name:',name)
print('gender:',gender)
print('age:',age)
print('city:',city)
#roll('Tom','F',city='shanxi')
def add_end(L=None):
if L is None:
L=[]
L.append('END')
return L
#print(add_end())
#-----------------------------
#variable argument
def change(*number):
sum=0
for i in number:
sum=sum+i*i
return sum