-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
111 lines (78 loc) · 1.99 KB
/
main.py
File metadata and controls
111 lines (78 loc) · 1.99 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
i = 1
while i < 10:
print(i)
i += 1
else :
print("i na less dan ten so we cyar go on")
list = ["Hamilton", "Sainz", "Norris"]
for driver in list:
print(driver)
for i in range(0, 50, 7):
print(i)
def add(a, b):
return a + b
def printPerson(name, age, height):
print(name, age, height)
def sayHello(fname, lname='Smith'):
print('Hello '+fname+' '+lname)
sayHello('John');
sayHello('Bill', 'Young');
sayHello('Jamiesion Beverly');
added = add(5, 4)
print(added)
jamie = printPerson("Jamieson Lancaster", 42, "5'9" )
list2 = [12, 24, 36, 48, 60, 66, 72, 78, 84]
list3 = ['Anjali', 'Renuah', 'Daniella', 'D`angelo', 'Rafael']
print(list2);
print(list2[-5])
print(list2[2:5])
print(len(list2))
list3.append('Brenda');
print(list3)
nameInList = list3.pop()
print(nameInList)
print(list3)
list5 = list3.copy()
print(list5)
doubledlist2 = [n*2 for n in list2]
print(doubledlist2)
list6 = list2 + list3
print(list6)
mydict = {
"name":"bob",
"age":45
}
print(mydict)
print(mydict['age'])
mydict['height'] = 6
print(mydict)
for key in mydict:
print(mydict[key])
if 'weight' in mydict:
print(mydict['weight'])
else:
print('no weight property!')
#Parent class
class Person:
def __init__(self, name, height, weight):
self.name = name;
self.height = height;
self.weight = weight;
def sayHello(self):
print("Hello! I'm a person, my name is", self.name)
# Child class inherits from Person
class Student(Person):
# super is the reference to the parent class Person so
# we call Person's constructor here to set the Person
# properties of the student instance
def __init__(self, stid, name, height, weight):
super().__init__(name, height, weight)
self.stid = stid
# override method of parent
def sayHello(self):
print("Hello! I'm a student, my name is", self.name)
bob = Person('bob', 12, 34)
sally = Student(123, 'sally', 7, 34)
bob.sayHello();
sally.sayHello();
print(bob.name);