diff --git a/InnekePuspitasari/List_Comprehensions.py b/InnekePuspitasari/List_Comprehensions.py new file mode 100644 index 0000000..639b904 --- /dev/null +++ b/InnekePuspitasari/List_Comprehensions.py @@ -0,0 +1,26 @@ +numbers = [10,20,30] +result = [n * 10 for n in numbers] + +print(result) + +#Equivalence vs Identity + # == for equality +a = [1,2,3] +b= a + +print (a == b) +print(a is b) + +#is for identity +a = [1,2,3] +b = [1,2,3] + +print(a == b) +print(a is b) + + + + + + + diff --git a/InnekePuspitasari/OOP1.py b/InnekePuspitasari/OOP1.py new file mode 100644 index 0000000..7974729 --- /dev/null +++ b/InnekePuspitasari/OOP1.py @@ -0,0 +1,8 @@ +class employee : + empCount = 0 + +def employee(self): + print("Total employee %d" % employee.empCount) + +def __init__(self, name, salary): + print("con") \ No newline at end of file diff --git a/InnekePuspitasari/Overloading.py b/InnekePuspitasari/Overloading.py new file mode 100644 index 0000000..1d36160 --- /dev/null +++ b/InnekePuspitasari/Overloading.py @@ -0,0 +1,14 @@ +class K: + def __init__(self, k): + self.k = k + + # adding two objects + def __add__(self, o): + return self.k + o.k +ob1 = K(1) +ob2 = K(2) +ob3 = K("Geeks") +ob4 = K("For") + +print(ob1 + ob2) +print(ob3 + ob4) \ No newline at end of file diff --git a/InnekePuspitasari/class_computer.py b/InnekePuspitasari/class_computer.py new file mode 100644 index 0000000..ca412b3 --- /dev/null +++ b/InnekePuspitasari/class_computer.py @@ -0,0 +1,18 @@ +class computer: + + def __init__(self): + self.__maxprice = 900 + def sell (self): + print("selling Price: {}".format(self.__maxprice)) + def setMaxprice(self, price): + self.__maxprice = price + +c = computer() +c.sell() + +#change the price +c.__maxprice=1000 +c.sell() + +c.setMaxprice(1000) +c.sell() \ No newline at end of file diff --git a/InnekePuspitasari/dictionary.py b/InnekePuspitasari/dictionary.py new file mode 100644 index 0000000..b4073c8 --- /dev/null +++ b/InnekePuspitasari/dictionary.py @@ -0,0 +1,14 @@ +class OrangCantik : + def __init__(__args__): + pass + + +plants = {} +plants["durian"] = 10 +plants["rambutan"] = 30 +plants[1] = "rambutan" + +faisal = OrangCantik() +plants[faisal] = 1 + +print(plants) diff --git a/InnekePuspitasari/inheritence.py b/InnekePuspitasari/inheritence.py new file mode 100644 index 0000000..6914aa1 --- /dev/null +++ b/InnekePuspitasari/inheritence.py @@ -0,0 +1,28 @@ +#parent class +class flower: + def __init__(self): + print("flower is ready") + + def whoisThis(self): + print("flower") + + def color(self): + print("color is red") + +#child class +class rose(flower): + def __init__(self): + #call super() fungtion + super().__init__() + print("rose is ready") + + def whoisThis(self): + print("rose") + + def smell(self): + print("smell nice") + +lil = rose() +lil.whoisThis() +lil.color() +lil.smell() \ No newline at end of file diff --git a/InnekePuspitasari/list.py b/InnekePuspitasari/list.py new file mode 100644 index 0000000..21e8b13 --- /dev/null +++ b/InnekePuspitasari/list.py @@ -0,0 +1,13 @@ +my_list = [] + +my_list.append(1) +my_list.append(2) +my_list.append(3) + +my_list.append(("yogi","imam")) + +plants = {} +plants["pisang"] = 23 +my_list.append(plants) + +print(my_list) diff --git a/InnekePuspitasari/list_2D.py b/InnekePuspitasari/list_2D.py new file mode 100644 index 0000000..68d2f0e --- /dev/null +++ b/InnekePuspitasari/list_2D.py @@ -0,0 +1,14 @@ +list2d = [] +list2d.append([]) +list2d.append([]) + +list2d[0].append(1) +list2d[0].append(2) + +list2d[1].append(3) +list2d[1].append(4) + +for y in list2d: + for x in y : + print(x, end=" ") + print() \ No newline at end of file diff --git a/InnekePuspitasari/list_loop.py b/InnekePuspitasari/list_loop.py new file mode 100644 index 0000000..1a9abe7 --- /dev/null +++ b/InnekePuspitasari/list_loop.py @@ -0,0 +1,3 @@ +students=["inneke","suci","dewi","dinda","zahra"] +for student in students: + print (student) \ No newline at end of file diff --git a/InnekePuspitasari/list_method.py b/InnekePuspitasari/list_method.py new file mode 100644 index 0000000..4a705b5 --- /dev/null +++ b/InnekePuspitasari/list_method.py @@ -0,0 +1,19 @@ +students = ["keke"] +students.append("sari") +print(students) + +students.insert(1, "Puspita") +print(students) + +girl_students = ["inneke","suci","dewi","dinda","zahra"] +students.extend(girl_students[0:5]) +print(students) + +students.sort() +print(students) + +students.reverse() +print(students) + +students.remove("sari") +print(students) \ No newline at end of file diff --git a/InnekePuspitasari/methodOOP.PY b/InnekePuspitasari/methodOOP.PY new file mode 100644 index 0000000..ae7411f --- /dev/null +++ b/InnekePuspitasari/methodOOP.PY @@ -0,0 +1,17 @@ +class Employe: + empCount=0 + + def __init__(self, name, salary): + self.name = name + self.salary = salary + Employe.empCount +=1 + + def displayCount(self): + print("total Employe %d" % Employe.empCount) + + def displayEmploye(self): + print("name : ", self.name, ", salary : ", self.salary) + +emp = Employe("NANI", 200) +emp.displayCount() +Employe.empCount \ No newline at end of file diff --git a/InnekePuspitasari/oop_exampl.py b/InnekePuspitasari/oop_exampl.py new file mode 100644 index 0000000..153a8a0 --- /dev/null +++ b/InnekePuspitasari/oop_exampl.py @@ -0,0 +1,22 @@ +class Employee: + empCount = 0 + + def Employee(self): + print("Total Employee %d" % Employee.empCount) + + def __init__(self, name, salary): + print("constructor created") + self.name = name + self.salary = salary + Employee.empCount += 1 + + def displayCount(self): + print("Total Employee %d" % Employee.empCount) + + def displayEmployee(self): + print("Name : ", self.name, ", Salary: ", self.salary) + +emp1 = Employee("kiki", 2000) +#emp1.Employee() +emp1.displayEmployee() +emp2 = Employee("riri", 5000) \ No newline at end of file diff --git a/InnekePuspitasari/polymorph.py b/InnekePuspitasari/polymorph.py new file mode 100644 index 0000000..2e88d01 --- /dev/null +++ b/InnekePuspitasari/polymorph.py @@ -0,0 +1,27 @@ +class Parrot: + + def fly(self): + print("Parrot can fly") + + def swim(self): + print("Parrot can't swim") + +class Penguin: + + def fly(self): + print("Penguin can't fly") + + def swim(self): + print("Penguin can swim") + +# common interface +def flying_test(bird): + bird.fly() + +#instantiate objects +blu = Parrot() +peggy = Penguin() + +# passing the object +flying_test(blu) +flying_test(peggy) diff --git a/InnekePuspitasari/tuple.py b/InnekePuspitasari/tuple.py new file mode 100644 index 0000000..8c4dcd3 --- /dev/null +++ b/InnekePuspitasari/tuple.py @@ -0,0 +1,2 @@ +my_tuple = tuple(["box","blue"]) +print(my_tuple) \ No newline at end of file diff --git a/InnekePuspitasari/tuple_immutable.py b/InnekePuspitasari/tuple_immutable.py new file mode 100644 index 0000000..9656fcd --- /dev/null +++ b/InnekePuspitasari/tuple_immutable.py @@ -0,0 +1,2 @@ +tuple = ('iguana','axolotl','snake') +tuple[0] = 'iguana' \ No newline at end of file diff --git a/InnekePuspitasari/tuple_packUnpack.py b/InnekePuspitasari/tuple_packUnpack.py new file mode 100644 index 0000000..5aca5c5 --- /dev/null +++ b/InnekePuspitasari/tuple_packUnpack.py @@ -0,0 +1,5 @@ +pair= ("iguana","axolotl") + +(key, value) = pair +print(key) +print(value) diff --git a/kekek02/OOP b/kekek02/OOP new file mode 100644 index 0000000..80262dc --- /dev/null +++ b/kekek02/OOP @@ -0,0 +1,28 @@ +#parent class +class flower: + def __init__(self): + print("flower is ready") + + def whoisThis(self): + print("flower") + + def color(self): + print("color is red") + +#child class +class rose(flower): + def __init__(self): + #call super() fungtion + super().__init__() + print("rose is ready") + + def whoisThis(self): + print("rose") + + def smell(self): + print("smell nice") + +lil = rose() +lil.whoisThis() +lil.color() +lil.smell()