- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunc.py
More file actions
Latest commit
58 lines (49 loc) · 1.27 KB
/
Copy pathFunc.py
File metadata and controls
58 lines (49 loc) · 1.27 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
importmath
defabs(x):
ifx<0:
return-x
else:
returnx
# This is a function that do nothing:
# pass is like todo in Java, without pass there would an error
defnon():
pass
# abs(x) more compatible
defabs(x):
ifnotisinstance(x, (int, float)):
raiseTypeError('bad operand type')
ifx<0:
return-x
else:
returnx
defmove(x, y, step, angle=0):
nx=x+step*math.cos(angle)
my=y-step*math.sin(angle)
returnnx, ny
# Note that the return dose not return multiple value but a tuple data struct like (nx, ny)
# If there is no return syntax in a function, the function return None by default
defpower(x, n=2):
s=1
whilen>0:
n-=1
s*=n;
returns
# To be fixed:
# draw_circle(0, 0, 20, linecolor=0xffff00, fillcolor=0xff00ff, penwidth=5)
# The above line will raise a NameError called: name 'draw_circle' is not defined
defadd_append(L[]):
returnL.append('END')
# This will cause error when no paramater is passed to the function
# Use the below instead:
defadd_append(L=None):
ifLisNone:
returnL= []
else:
returnL.append('END')
# The function that can change the number of paramaters
# The function chage the paramaters into set or tuple by default
defcalc(*numbers):
sum=0
forninnumbers:
sum+=n*n
returnsum