-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython function.py
More file actions
85 lines (71 loc) · 1.71 KB
/
python function.py
File metadata and controls
85 lines (71 loc) · 1.71 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
def my_function():
print("Hello from a function")
my_function()
print()
def my_function(fname): #arguments
print(fname + " Refsnes")
my_function("Emil")
my_function("Tobias")
my_function("Linus")
print()
def my_function(fname, lname):
print(fname + " " + lname)
my_function("Emil", "Refsnes")
print()
def my_function(fname, lname):
print(fname + " " + lname)
my_function("Emil", 'doc')
print()
def my_function(*kids): #if the number of arguments is unknown
print("The youngest child is " + kids[2])
my_function("Emil", "Tobias", "Linus")
print()
def my_function(*kids):
print("The youngest child is " + kids[0])
my_function("Emil", "Tobias", "Linus")
print()
def my_function(child3, child2, child1):
print("The youngest child is " + child3)
my_function(child1 = "Emil", child2 = "Tobias", child3 = "Linus")
print()
def my_function(**kid): #if the number of keyword arguments is unknown....kwargs-keyword argument
print("His last name is " + kid["lname"])
my_function(fname = "Tobias", lname = "Refsnes")
print()
def my_function(country = "Norway"):
print("I am from " + country)
my_function("Sweden")
my_function("India")
my_function()
my_function("Brazil")
print()
def my_function(food):
for x in food:
print(x)
fruits = ["apple", "banana", "cherry"]
my_function(fruits)
print()
def my_function(x):
return 5 * x
print(my_function(3))
print(my_function(5))
print(my_function(9))
print()
:
def my_function(x):
print( 5 * x)
my_function(3)
my_function(5)
my_function(9)
print()
def myfunction():
pass #this prevents an error
def tri_recursion(k):
if(k > 0):
result = k + tri_recursion(k - 1)
print(result)
else:
result = 0
return result
print("\n\nRecursion Example Results")
tri_recursion(6)