-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.py
More file actions
48 lines (46 loc) · 1.13 KB
/
Copy pathfunction.py
File metadata and controls
48 lines (46 loc) · 1.13 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
#function is a block of code that executes code
def hello():
print("This is my first function")
hello()
def calculate( x=12, y=45):
print(x*y)
calculate()
#functions with variiables
def majina(fname, lname):
print(fname+ " "+ lname)
majina("solomon", "njogo")
majina("stephen", "thuita")
majina("susan", "muthoni")
#functions with an argument
def greetings(name, greetings="hello"):
print(greetings+ " "+ name)
greetings("solomon")
greetings("niaje", "solo")
greetings("solo", "niaje")
#functions with an argument
def gari(model, company="Tesla"):
print(company+ " "+model)
gari("model s")
gari("model 3")
gari("model x")
gari("model y")
#return the maximum value in data
def maxvalue(a, b, c, d, e, f):
return max(a, b, c, d, e, f)
result=maxvalue(7,9,1,8,17,45)
print(result)
#return the minimum value in data
def minvalue(a, b, c, d, e, f):
return min(a, b, c, d, e, f)
result=minvalue(99,45,12,89,5,1)
print(result)
#function that sorts
def sort_list(lst):
return sorted(lst)
answer=sort_list([3,9,0,2,7,11,5,5,4,2])
print(answer)
#function that prints out numbers
def print_numbers(n):
for i in range(n):
print(i)
print_numbers(5)