-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmore_functions.py
More file actions
58 lines (36 loc) · 1.14 KB
/
more_functions.py
File metadata and controls
58 lines (36 loc) · 1.14 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
#imports
#basic function for area
def area(a, b):
return a * b
print(area(4,5))
#explicit function argument
def area_2(a,b):
try:
if(isinstance(a, (int, float)) and isinstance(b, (int, float))):
return a * b
else:
return (float(a) * float(b))
except ValueError:
return "The first parameter: [%s] or the second parameter [%s] were not valid arguments please enter either a float or an int" % (a, b)
#quick test
print(area_2(4,5)) #should be 20
print(area_2(4.1, 5.1)) #should be 20.909...
print(area_2("4.1", "5.1")) #shoudl be 20.909..
print(area_2("this should fail", "this should fail")) #should throw
#indefinate paramters
def average_basic(*args):
return (sum(args)/len(args))
#quick test
print(average_basic(1,2,3,4,5,6,7))
#sorting strings alphabetically
def alphabetize_list(*args):
#converting the tuple to a list for processing
args = [i.upper() for i in args]
return sorted(args)
#quick test
print(alphabetize_list("twinkle","twinkle","little", "star"))
#kwargs (key word arguments)
def mean(**kwargs):
return kwargs
#quick test
print(mean(a=1, b=2, c=3))