-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
211 lines (166 loc) · 3.8 KB
/
functions.py
File metadata and controls
211 lines (166 loc) · 3.8 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def add_func():
a = 5
b = 10
c = a + b
return c
result = add_func()
print("The result of the addition is:", result)
#dynamically took values
def add_func(a, b):
c = a + b
return c
a = 10
b = 25
result = add_func(a, b)
print( result)
def add_func(a, b):
c = a + b
print("return value")
return c
a = 100
b = 250000
result = add_func(a, b)
print( result)
def add_func(a, b):
c = a + b
print("return value")
return c
x = 100
z = 250000
result = add_func(x, z)
print( result)
def add_func(a, b, c):
c = a + b + c
print("return value")
return c
x = 100
j = 100
z = 250000
result = add_func(x, z, j)
print( result)
def profile(name, age, city, email, number):
print(f"name: (name)")
print(f"age: (age)")
print(f"city: (city)")
print(f"email: (email)")
print(f"number: (number)")
return name, age, city, email, number
name = 'john',
age = 30,
city = 'new York',
email = 'ali@gmail.com',
number = 123456789
result = profile(name, age, city, email, number)
print(result)
#make a function in which we can add, mult, sub, div any value
def func(a, b):
add = a + b
sub = a - b
mult = a * b
div = a / b
return add, sub, mult, div
a = 10
b = 25
result = func(a, b)
print( result)
def profile(dict1):
print(f"name: (name)")
print(f"age: (age)")
print(f"city: (city)")
print(f"email: (email)")
print(f"number: (number)")
return name, age, city, email, number
dict1 = {
'name': 'john',
'age': 30,
'city':'new York',
'email': 'ali@gmail.com',
'number': 123456789
}
result = profile(dict1)
print(result)
def profile(dicr):
name = dicr.get('name')
age = dicr.get('age')
city = dicr.get('city')
email = dicr.get('email')
number = dicr.get('number')
return name, age
dict1 = {
'name': 'john',
'age': 30,
'city':'new York',
'email': 'ali@gmail.com',
'number': 123456789
}
result = profile(dict1)
print(result)
def add_fun(*args):
# a = a + b
# b = a - b
# c = a * b
# d = a / b
# print('a value is:', a)
# print('b value is:', b)
print('b value is:', c, args [0])
type_form = type(args)
print('type of arg is:', type_form)
#print('c value is:', c, args.get ('c', 0)
print ('return value')
# return c, d, f, g
a = 50
b = 107
c = 5
g = 10
k = 20
result = add_fun([b, a, c, g, k])
def my_function(child3, child2, child1):
print("The youngest child is " + child3)
my_function(child1 = "Emil", child2 = "Tobias", child3 = "Linus")
def my_function(**kid):
print("His last name is " + kid["lname"])
my_function(fname = "Tobias", lname = "Refsnes")
def my_function(**veg):
print("We can also eat this vegetable without cooking: " + veg.get('veg3'))
my_function(veg1 = "Okra", veg2 = "Pease", veg3 = "carrot")
def res(fs, op, tr):
print("this is a function with three parameters")
ds = res(fs=10, op=20, tr=30)
print(ds)
#by Default Parameter Value
def my_function(country = "Norway"):
print("I am from " + country)
my_function("Sweden")
my_function("India")
my_function()
my_function("Brazil")
#Task1
a = [1, 2, "Nothing", 4, 5, "I am here", 7, False, 9, 10.55]
def function(a):
for i in a:
print(i)
if i == 5:
print("reached")
function(a)
#Task2
def calculator (a, b, operation):
if operation == "add":
print("Addition:", a + b)
elif operation == "sub":
print("Subtraction:", a - b)
elif operation == "mul":
print("Multiplication:", a * b)
elif operation == "div":
print("Division:", a / b)
else:
print("error")
a = 5
b = 5
operation = "add"
operation = "sub"
operation = "sub"
operation = "div"
calculator(b, a, "add")
calculator(b, a, "sub")
calculator(b, a, "mul")
calculator(b, a, "div")