diff --git a/H071221008/Praktikum7/no (1).py b/H071221008/Praktikum7/no (1).py new file mode 100644 index 0000000..1db12a1 --- /dev/null +++ b/H071221008/Praktikum7/no (1).py @@ -0,0 +1,27 @@ +import re + + +string_s= input('masukkan String S : ') +print(len(string_s)) +regex1 = r'[0?2?4?6?8?_?a-z?A-Z]' +regex2 = r'[1?3?5?7?9?]' + +match= re.findall(regex2, string_s[0:40]) +match2= re.findall(regex1, string_s[40:45]) + +print(match, match2) +if match: + print('false') + exit() +elif match2: + print('false') + exit() + + +if (len(string_s)) == 45: + print('true') +else: + print('false') + + + \ No newline at end of file diff --git a/H071221008/Praktikum7/no (2).py b/H071221008/Praktikum7/no (2).py new file mode 100644 index 0000000..0518491 --- /dev/null +++ b/H071221008/Praktikum7/no (2).py @@ -0,0 +1,28 @@ +import re + +def ipv4 (ip) : + pola1= r"(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])" + match1 = fr"{pola1}\.{pola1}\.{pola1}\.{pola1}" + return re.fullmatch (match1,ip) +#200-249 +2 [0] [0] +2 [4] [9] +def ipv6 (ip) : + pola2 = r"([0-9A-Fa-f]{1,4})" + match2 = fr"{pola2}:{pola2}:{pola2}:{pola2}:{pola2}:{pola2}:{pola2}:{pola2}" + return re.fullmatch (match2,ip) + +loop=int(input()) +listIP=[] +for i in range(loop) : + adressIP=input() + listIP.append(adressIP) +for j in listIP: + if ipv4 (j) : + print ("IPv4") + elif ipv6 (j) : + print ("IPv6") + else : + + + print ("Bukan IP Address") \ No newline at end of file diff --git a/H071221008/Praktikum7/pp8.py b/H071221008/Praktikum7/pp8.py new file mode 100644 index 0000000..70cea65 --- /dev/null +++ b/H071221008/Praktikum7/pp8.py @@ -0,0 +1,22 @@ +# namaHewan1 = "anjing" +# jumlahHenwan1 = 4 +# namaHewan2 = "burung" +# jumlahHewan = 2 +# print(namaHewan) + +class Burung: + def __init__ (self, inputJenis, inputWarna): + self.jenis = inputJenis + self.warna = inputWarna + print("objek Berhasil Dibuat") + + # def say_hello(): + # print("Halo World") # pembuatan Blueprint/Template + +beo = Burung("Beo", "Hijau") # objek penggunaan Blueprint/Template + +print(beo.__dict__) +print(beo.jenis) +print(beo.warna) + +#beo.jenis = inputjenis \ No newline at end of file diff --git a/H071221008/Praktikum7/pp81.py b/H071221008/Praktikum7/pp81.py new file mode 100644 index 0000000..980e9bf --- /dev/null +++ b/H071221008/Praktikum7/pp81.py @@ -0,0 +1,16 @@ +class say_hello : + + def __init__(self, inputNama) : + self.nama = inputNama + + def helloNama(self, nama) : + print("Halo", nama) + + def helloWaktu(self, waktu): + print(f"Selamat {waktu} kerasnya dunia") + +nama1 = say_hello("Budianto Nugraha") + +print.waktu("subuh") +print(nama1.nama) + diff --git a/H071221008/praktikum10/praktikum101.py b/H071221008/praktikum10/praktikum101.py new file mode 100644 index 0000000..115a807 --- /dev/null +++ b/H071221008/praktikum10/praktikum101.py @@ -0,0 +1,117 @@ +# Membuat sebuah program yang jika dijalankan akan menampilkan menu + +import re +import os + +def menu(): + print('=' * 50) + print('Selamat Datang Silahkan Pilih Opsi Menu Anda') + print('1. Detail Anda') + print('2. Ubah Nama') + print('3. Jumlah Data pada File') + print('4. Save Data pada File') + print('5. Buat Data Baru') + print('6. Keluar') + +data = None + +while True: + menu() + opsi = input("Silahkan Pilih Opsi Anda : ") + + try: + opsi = int(opsi) + except: + print("Inputan salah") + else: + match opsi: + case 1: + if data == None: + print('=' * 50) + print('Data Saat Ini Kosong') + else: + print('=' * 50) + print('Nama :', data['Nama']) + print('Email :', data['Email']) + print('Password :', data['Password']) + case 2: + if data == None: + print('=' * 50) + print('Data Saat Ini Kosong') + else: + print('=' * 50) + data['Nama'] = input("Silahkan Input Nama Baru : ") + case 3: + print('=' * 50) + banyak_baris = 0 + file = input("Silahkan Masukkan Nama File : ") + '.txt' + print("Berhasil") + try: + with open(file) as baca: + data_file = re.findall(fr"@student\.unhas\.ac\.id", baca.read()) + print(f"Jumlah Data Adalah : {data_file.count('@student.unhas.ac.id')}") + + except: + print("Tidak Terdapat File dengan nama " + file) + print("Jumlah Data Pada File : 0 Data") + case 4: + if data == None: + print('=' * 50) + print('Data Saat Ini Kosong') + else: + print('=' * 50) + file_name = input("Silahkan Masukkan Nama File : ") + '.txt' + print("Berhasil") + if os.path.exists(file_name): + with open(file_name, 'a') as file: + file.write(f"\n|Nama\t\t: {data['Nama']}\n") + file.write(f"|Email\t\t: {data['Email']}\n") + file.write(f"|Password\t: {data['Password']}\n") + file.write(f"=" * 100) + else: + with open(file_name, 'x') as file: + file.write("+"+"=" * 100) + + file.write(f"\n|Data Yang Tersimpan\n") + file.write("+"+"=" * 100) + file.writelines(f"\n|Nama\t\t: {data['Nama']}\n") + file.write(f"|Email\t\t: {data['Email']}\n") + file.write(f"|Password\t: {data['Password']}\n") + file.write("+"+"=" * 100) + data = None + case 5: + data = { + "Nama": "" , + "Email": "", + "Password": "" + } + print('=' * 50) + data["Nama"] = input("Silahkan Masukkan Nama Anda : ") + while True: + email = input("Silahkan Masukkan Email Anda : ") + if re.fullmatch("^[a-z0-9]{1,}(@student\.unhas\.ac\.id$)", (email)): + data["Email"] = email + break + else: + print('=' * 50) + print("Email Yang Anda Masukkan Salah") + print('=' * 50) + while True: + password = input("Silahkan Masukkan Password Anda : ") + if re.fullmatch(".{8,20}", (password)): + if re.findall("[A-Z]+", (password)) and re.findall("[a-z]+", (password)) and re.findall("[0-9]+", (password)): + data["Password"] = password + break + else: + print('=' * 50) + print("Password Yang anda masukkan terlalu lemah") + print("Gunakan Minimal 1 Huruf Kapital, Huruf Kecil, dan Angka") + print('=' * 50) + else: + print('=' * 50) + print("Password Harus Memiliki Panjang 8-20 Karakter") + print('=' * 50) + case 6: + print('=' * 50) + print('Sampai Jumpa Lagi') + break \ No newline at end of file diff --git a/H071221008/praktikum10/praktikum102.py b/H071221008/praktikum10/praktikum102.py new file mode 100644 index 0000000..7d8759e --- /dev/null +++ b/H071221008/praktikum10/praktikum102.py @@ -0,0 +1,53 @@ +from abc import ABC, abstractclassmethod +# Polymorphism = parent class punya fungsi sama dengan child class tapi beda isinya. +# Encapsulation = membatasi akses atribut +# Inheritance = warisan +# Abstract = cetak biru dari class + +#Abstract Class +class Tanaman(ABC): + def mengeluarkan_bau(self): + pass + +#class parent +class Bunga(Tanaman): + def __init__(self, jenis, beracun): + self._jenis= jenis #encapsulation + self._beracun= beracun #encapsulation + + # method bunga + def getjenis(self): + return self._jenis + # method bunga + def setjenis(self, jenis): + self._jenis= jenis + # method bunga + def mengeluarkan_bau(self): + pass + +#class child +class Rafflesia(Bunga): #inheritance (Rafflesia inheritance dari bunga) + def __init__(self, jenis, beracun): + super().__init__(jenis, beracun) + # method Raflessia + def mengeluarkan_bau(self): + print('bunga rafflesia mengeluarkan bau tidak sedap') + +class Melati(Bunga): #inheritancde + def __init__(self, jenis, beracun): + super().__init__(jenis, beracun) + # method melati + def mengeluarkan_bau(self): + print('bunga melati mengeluarkan bau harum') + +#interface +def tes_mengeluarkan_bau(bunga): #polymorphism + bunga.mengeluarkan_bau() + +#object +a = Rafflesia("rafflesia", True) +b = Melati("melati", False) + +#pemanggilan interface pd kedua object +a.mengeluarkan_bau() #polymorphism +b.mengeluarkan_bau() #polymorphism diff --git a/H071221008/praktikum9/Hero.py b/H071221008/praktikum9/Hero.py new file mode 100644 index 0000000..5c14132 --- /dev/null +++ b/H071221008/praktikum9/Hero.py @@ -0,0 +1,62 @@ +class Human: + def __init__(self, name, position): + self.name = name + self.__pos_x = position + + def setMovement(self, move): + if move == 'L': + self.__pos_x -= self._speed + if move == 'R': + self.__pos_x += self._speed + +class Hero(Human): + def __init__(self, name, pos_x): + super().__init__(name, pos_x) + self._power = 15 + self.health = health + self._armor = 15 + self._speed = 3 + + def attack(self, target): + target.health -= self._power + + def getHealth(self): + return self.health + + def getSpeed(self): + return self._speed + +class Warrior(Hero): + def __init__(self, name, pos_x): + super().__init__(name, pos_x) + self._power = 26 + self._armor = 30 + + def special(self, target): + self._armor = 45 + self._power = 32 + target.health -= self._power + +class Assassin(Hero): + def __init__(self, nama, pos_x): + super().__init__(nama, pos_x) + self._power = 35 + self._speed = 4 + + def special(self, target): + self._speed = 7 + self._power = 42 + target.health -= self._power + +class Support(Hero): + def __init__(self, name, pos_x): + super().__init__(name, pos_x) + self._health = 500 + self._armor = 8 + self._speed = 4 + + def special(self, target): + self._speed = 6 + target.health += 150 + +health = int(input()) diff --git a/H071221008/praktikum9/__pycache__/Hero.cpython-310.pyc b/H071221008/praktikum9/__pycache__/Hero.cpython-310.pyc new file mode 100644 index 0000000..68c16ea Binary files /dev/null and b/H071221008/praktikum9/__pycache__/Hero.cpython-310.pyc differ diff --git a/H071221008/praktikum9/no2.py b/H071221008/praktikum9/no2.py new file mode 100644 index 0000000..55e970d --- /dev/null +++ b/H071221008/praktikum9/no2.py @@ -0,0 +1,27 @@ +from Hero import Warrior, Assassin, Support + +warrior = Warrior("bambang", pos_x=10) +assassin = Assassin("joko", pos_x=25) +support = Support("udin",pos_x=30) + +# sebelum +print("health (before)", warrior.getHealth()) +assassin.special(warrior) + +# sesudah +print("health (after)", warrior.getHealth()) + +print("-"*10) + +# sebelum +print("Warrior (health)", warrior.getHealth()) +print("Support (speed) : ",support.getSpeed()) +support.special(warrior) + +# sesudah +print("Warrior (health)", warrior.getHealth()) +print("Support (speed): ",support.getSpeed()) + + + + diff --git a/H071221008/praktikum9/pp10.py b/H071221008/praktikum9/pp10.py new file mode 100644 index 0000000..83c7e90 --- /dev/null +++ b/H071221008/praktikum9/pp10.py @@ -0,0 +1,18 @@ +from abc import ABC, abstractmethod + +class Human(ABC): + + @abstractmethod + def makan(self): + print("Manusia itu sudah makan") + +class Hero(Human): + + def makan(self): + print("Manusia itu sudah makan") + + +person = Hero() +person.makan() + +