Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Chapter01/__pycache__/do_something.cpython-310.pyc
Binary file not shown.
10 changes: 5 additions & 5 deletions Chapter01/classes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class namakelas:
common = 10
def __init__ (self):
def __init__ (self): #memanggil constructor
self.myvariable = 3
def myfunction (self, arg1, arg2):
def myfunction (self, arg1, arg2): #instance method
return self.myvariable

instance = namakelas()
print("instance.myfunction(1, 2)" , instance.myfunction(1, 2))
print("instance.myfunction(1, 2)" , instance.myfunction(1, 2)) #memanggil instance method

instance2 = namakelas()
print("instance.common ",instance.common)
Expand Down Expand Up @@ -36,10 +36,10 @@ def __init__ (self, arg1):
print (arg1)

instance = AnotherClass ("hello")
print("instance.myfunction (1, 2) " , instance.myfunction (1, 2))
print("instance.myfunction (1, 2) " , instance.myfunction (1, 2)) #memanggil instance method

instance.test = 10
print("instance.test " , instance.test)
print("instance.test " , instance.test) #memanggil instance method



Expand Down
11 changes: 9 additions & 2 deletions Chapter01/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# kami memeriksa apakah angkanya positif atau negatif atau nol dan
# tampilkan pesan yang sesuai

num = 1
num = 0

# Try these two variations as well:
# num = 0
Expand All @@ -23,7 +23,8 @@
numbers = [6, 6, 3, 8, -3, 2, 5, 44, 12]

# variable to store the sum
sum = 0
sum = -35
# sum = 0

# iterate over the list
for val in numbers:
Expand All @@ -32,3 +33,9 @@
# Output: The sum is 48
print("The sum is", sum)

if sum > 0:
print("Positive number")
elif sum == 0:
print("Zero")
else:
print("Negative number")
18 changes: 10 additions & 8 deletions Chapter01/file.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
f = open ('test.txt', 'w')
f.write ('first line of file \n')
f = open ('test.txt', 'w') #menulis dalam format text.
f.write ('first line of file \n') #menulis string didalam file yang telah dibuka

f.write ('second line of file \n')
f.write ('second line of file \n') #menulis string didalam file yang telah dibuka

f.close() #menutup file
f = open ('test.txt') #membuka file pada direktori saat ini untuk dibaca
content = f.read() #membaca string dari file
print (content) #menampilkan konten yang ada didalam file

f.close() #menutup file

f.close()
f = open ('test.txt')
content = f.read()
print (content)

f.close()
12 changes: 6 additions & 6 deletions Chapter01/multiprocessing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
import multiprocessing


if __name__ == "__main__":
if __name__ == "__main__": # Memastikan code ada pada main function/tidak diimport.
start_time = time.time()
size = 10000000
procs = 10
jobs = []
for i in range(0, procs):
for i in range(0, procs): #Membuat proses
out_list = list()
process = multiprocessing.Process\
(target=do_something,args=(size,out_list))
(target=do_something,args=(size,out_list)) # Menginisiasi proses dengan argument
jobs.append(process)

for j in jobs:
j.start()
j.start() # memulai proses

for j in jobs:
for j in jobs: # menyelesaikan proses
j.join()

print ("List processing complete.")
print ("List processing complete.") # proses selesai
end_time = time.time()
print("multiprocesses time=", end_time - start_time)
10 changes: 5 additions & 5 deletions Chapter01/multithreading_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
import time
import threading

if __name__ == "__main__":
if __name__ == "__main__": # Memastikan code ada pada main function/tidak diimport.
start_time = time.time()
size = 10000000
threads = 10
jobs = []
for i in range(0, threads):
out_list = list()
thread = threading.Thread(target=do_something(size, out_list))
thread = threading.Thread(target=do_something(size, out_list)) # Membuat Thread
jobs.append(thread)
for j in jobs:
j.start()
j.start() # memulai proses


for j in jobs:
j.join()
j.join() # menyelesaikan proses

print ("List processing complete.")
print ("List processing complete.") #proses selesai
end_time = time.time()
print("multithreading time=", end_time - start_time)

Binary file not shown.
Binary file not shown.
Binary file not shown.
34 changes: 34 additions & 0 deletions Chapter01/studiKasus/classes_studikasus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Karyawan:
def __init__(self, nama, gaji):
self.nama = nama
self.gaji = gaji

def displayKaryawan(self):
print ("nama : ", self.nama, ", gaji: ", self.gaji)

emp1 = Karyawan("Udin Wazowski", 2000)
emp2 = Karyawan("Astoria Greengrass", 5000)

emp1.displayKaryawan()
emp2.displayKaryawan()

emp1 = Karyawan("Koro koro", 8000)
emp2 = Karyawan("Kucu kucu", 5000)

emp1.displayKaryawan()
emp2.displayKaryawan()

class Posisi(Karyawan):
def __init__(self, nama, posisi, gaji):
self.nama = nama
self.posisi = posisi
self.gaji = gaji

def display(self):
print("Nama : ", self.nama, ", posisi : ", self.posisi, ", gaji : ", self.gaji)

emp1 = Posisi("TTesting", 'Software Engineer', 4000)
emp2 = Posisi("Astoria", 'HRD', 5000)

emp1.display()
emp2.display()
28 changes: 28 additions & 0 deletions Chapter01/studiKasus/dir_studikasus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
gaji = int(input('Masukan Gaji Karyawan Anda: '))

if gaji > 1000000:
print("Selamat Menikmati Uang hasil Kerja Anda")
elif gaji == 0:
print("Anda tidak digaji :(")
else:
print("Jangan Boros ya.")


###########
numbers = [13, 15, 20, 22, -99, 50, 4]

sum = int(input('Masukan Angka Bebas: '))
# sum = 0
for val in numbers:
sum = sum+val

print("The sum is", sum)

if sum > 0:
print("Positive number")
elif sum == 0:
print("Zero")
else:
print("Negative number")


4 changes: 4 additions & 0 deletions Chapter01/studiKasus/do_studikasus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def totalKaryawan(count, list_karyawan):
for i in range(count):
list_karyawan = ['Udin Wazowski', 'Jon cool', 'Asoyy gamink']
print('Nama Karyawan : ', list_karyawan)
15 changes: 15 additions & 0 deletions Chapter01/studiKasus/file_studikasus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
f = open ('file_studikasus.txt', 'w')
nama = input('Masukan Nama Anda :')
alamat = input('Masukan Alamat Anda :')
hobi = input('Masukan Hobi Anda :')
f.write (nama + '\n')

f.write (alamat + '\n')
f.write (hobi + '\n')

f.close()
f = open ('file_studikasus.txt')
content = f.read()
print (content)

f.close()
50 changes: 50 additions & 0 deletions Chapter01/studiKasus/flow_studikasus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
nilai = int(input('Masukan Nilai Ujian Anda : '))
if nilai >= 75:
print("Selamat Anda Lolos")
elif nilai == 0:
print("Anda Tidak Ikut Ujian")
else:
print("Anda Ikut Remedial")


# FOR
durasi_kerja = float(input('masukan durasi kerja: '))

if durasi_kerja > 8:
print("Durasi Kerja + Lembur")
elif durasi_kerja == 8:
print("Durasi Kerja Rata-rata")
else:
print("Durasi Kerja Dibawah Rata-Rata")


############1
total_durasi_kerja = [7,8,9]

durasi_lembur = 4
for val in total_durasi_kerja:
durasi_lembur = durasi_lembur+val

print("Total Semua Durasi Kerja", durasi_lembur)

if durasi_lembur > 12.00:
print("CAPEK")
elif durasi_lembur == 0.00:
print("Anda Kerja ?")
else:
print("Kerja Santai")


#WHILE
# Program to add natural numbers upto sum = 1+2+3+...+n

n = 10
# initialize sum and counter
sum = 0
i = 1
while i <= n:
sum = sum + i
i = i+1 # update counter

# print the sum
print("The sum is", sum)
22 changes: 22 additions & 0 deletions Chapter01/studiKasus/list_studikasus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
list_Perusahaan = ["Tech, Inc", 200000000, "Indddie", 10000000] #list
print(list_Perusahaan)
list_Perusahaan[0]
print(list_Perusahaan[0])
list_Perusahaan[-1]
print (list_Perusahaan[-1])

dict_perusahaan = {"nama_perusahaan":"Tech, Inc", "nama_ceo":"Mamank Racing"} #dictionary
print(dict_perusahaan)
dict_perusahaan["nama_perusahaan"]
print(dict_perusahaan["nama_perusahaan"])

dict_2 = {"key 1":"Udin Wazowski", 2:"Test Doang", "key 3":"Siapa Ya"}
print(dict_2)
dict_2[2]
print(dict_2[2])

status_perusahaan = ("Aktif", "Nonaktif") #tuple
print(status_perusahaan)

panjangData = len
print (panjangData(list_Perusahaan))
25 changes: 25 additions & 0 deletions Chapter01/studiKasus/multiprocessing_studikasus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from do_studikasus import totalKaryawan
import time
import multiprocessing

if __name__ == "__main__":
start_time = time.time()
size = 1000
procs = 10
list_karyawan = []
# out_list = list()
for i in range(0, procs):
out_list = list()
process = multiprocessing.Process\
(target=totalKaryawan,args=(size,out_list))
list_karyawan.append(process)

for j in list_karyawan:
j.start()

for j in list_karyawan:
j.join()

print ("List processing complete.")
end_time = time.time()
print("multiprocesses time=", end_time - start_time)
23 changes: 23 additions & 0 deletions Chapter01/studiKasus/multithreading_studikasus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from do_studikasus import totalKaryawan
import time
import threading

if __name__ == "__main__":
start_time = time.time()
size = 1000
procs = 10
process = []
for i in range(0, procs):
out_list = list()
thread = threading.Thread(target=totalKaryawan(size,out_list))
process.append(thread)

for j in process:
j.start()

for j in process:
j.join()

print ("List processing complete.")
end_time = time.time()
print("multithreading time=", end_time - start_time)
4 changes: 2 additions & 2 deletions Chapter02/Condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def consume(self):
condition.notify()

def run(self):
for i in range(20):
for i in range(5):
time.sleep(2)
self.consume()

Expand All @@ -50,7 +50,7 @@ def produce(self):
condition.notify()

def run(self):
for i in range(20):
for i in range(5):
time.sleep(0.5)
self.produce()

Expand Down
2 changes: 1 addition & 1 deletion Chapter02/Event.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, *args, **kwargs):
def run(self):
for i in range(5):
time.sleep(2)
item = random.randint(0, 100)
item = random.randint(0, 10)
items.append(item)
logging.info('Producer notify: item {} appended by {}'\
.format(item, self.name))
Expand Down
Loading