-
Notifications
You must be signed in to change notification settings - Fork 0
/
cap.py
46 lines (34 loc) · 1.02 KB
/
cap.py
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
# def closest(ts):
# min1=abs(ts[0])
# for i in ts:
# if(abs(i)<abs(min1)):
# min1=i
# print("Closest to zero for array 1: "+ str(min1))
def closest(ts):
min1=abs(ts[0])
for i in ts:
if(abs(i)<abs(min1)):
min1=i
print("Closest to zero in array: "+ str(min1))
array_1 = [5, 3.2, -1.2, -0.2, 7]
array_2 = [19, -20, -4.7, 6, 9, 42]
array_3 = [4, 0.3, -9, 8, 6, 14]
closest(array_3)
# Class and methods
class Person:
def __init__(self, name, sex, profession) -> None:
# data members (instance variable)
self.name = name
self.sex = sex
self.profession = profession
# Behavior (instance methods)
def show(self):
print('Name:', self.name, 'Sex:', self.sex, 'Profession:', self.profession)
# Behavior (instance methods)
def work(self):
print(self.name, 'working as a', self.profession)
# Create object of a class
person = Person('Mops', 'Male', 'Software Engineer')
# Call methods
person.show()
person.work()