-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonFunction.py
More file actions
88 lines (67 loc) · 1.57 KB
/
PythonFunction.py
File metadata and controls
88 lines (67 loc) · 1.57 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#Function is a block of code that works when callled upon
def my_function():
print("Waya")
my_function()
#adding arguments to a function
def sum(x,y):
a=x+y
print("Answer is=",a)
sum(10,20)
sum(50,70)
def multiplication(a,b):
m=a*b
print("Answer is=",m)
multiplication(7,5)
multiplication(47,72)
def sum(a,b):
x=a+b
return x
print(sum(10,5))
#arbitrary aerguments
def courses(*units):
for subjects in units:
print(subjects)
courses("data","cnn","oop2")
def course(*units):
for unit in units:
print(unit)
course("oop2","web","python")
#Arbitrary keyword arguments
def courses(**units):
for key,value in units.items():
print("{}:{}".format(key,value))
courses(first='data',second='python',third='ccn')
#default parameter value
def africa(country="kenya"):
print("I'm from "+ country)
africa()
africa("senegal")
#passing a list as an argument
def my_function(food):
for x in food:
print(x)
#fruits=["apple","banana","cherry"]
#my_function(fruits)
student={
"name":"Caleb",
"email":"caleb@gmail.com",
"regNo":"BSCIT-05-0000/2010"
}
print(student)
#area of a rectangle
def area_of_rectangle(L,W):
a=L*W
return a
print(area_of_rectangle(3,7))
#area of a circle
def area_of_circle(r):
pi=3.142
a= pi*(r*r);
print("Area of a circle is",a)
area_of_circle(7)
#area of a sphere
def volume_of_spere(r):
pi=3.142
v=4/3*pi*(r*r*r);
print("volume is",v)
volume_of_sphere(4)