diff --git a/H071221101/Tugas Praktikum 10/1.py b/H071221101/Tugas Praktikum 10/1.py new file mode 100644 index 0000000..ad87e68 --- /dev/null +++ b/H071221101/Tugas Praktikum 10/1.py @@ -0,0 +1,98 @@ +import re, os + +print('='*60) + +nama = [] +email = [] +password = [] +jumlah = 0 + +while True : + print("="*60) + print(f"Halo! silahkan pilih opsi : ") + print("="*60) + 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") + print("="*60) + + opsi = int(input("Opsi yang diinginkan : ")) + print("="*60) + + if opsi == 1 : + if len(nama) == 0 or len(email) == 0 or len(password) == 0: + print("Data saat ini kosong") + else : + print("Data anda adalah : ") + print(f"Nama : {nama}") + print(f"Email : {email}") + print(f"Password : {password}") + + elif opsi == 2 : + if len(nama) == 0 or len(email) == 0 or len(password) == 0: + print("Data saat ini kosong") + else : + ubah_nama = input("Silahkan input nama baru : ") + nama = ubah_nama + + elif opsi == 3 : + print(jumlah) + + + elif opsi == 4 : + if nama == [] and email == [] and password == [] : + print("Data saat ini masih kosong") + else : + if not os.path.isfile('Data.txt') : + with open ('Data.txt', 'w') as file : + file.write("=========================================\n") + file.write("Data yang Tersimpan\n") + file.write("=========================================\n") + file.write(f"|Nama : {nama} \n") + file.write(f"|Email :{email} \n") + file.write(f"|Password : {password} \n") + file.write("=========================================\n") + jumlah += 1 + file2 = open('Data.txt', 'a') + file2.write(f"|Nama : {nama} \n") + file2.write(f"|Email :{email} \n") + file2.write(f"|Password : {password} \n") + file2.write("=========================================\n") + jumlah += 1 + + + elif opsi == 5 : + namaBaru = input("Silahkan input nama : ") + nama = namaBaru + + while True : + pola = "[a-zA-Z0-9]+@student.unhas.ac.id" + emailBaru = input("Silahkan input email : ") + hasil = re.match(pola, emailBaru) + + if hasil == None : + print("Email yang Anda Masukkan Salah") + else : + email = emailBaru + break + + while True : + passwordBaru = input("Silahkan input password : ") + + if re.findall("[A-Z]", passwordBaru) != []: + if re.findall("[a-z]", passwordBaru) != [] : + if re.findall("[0-9]", passwordBaru) != [] : + if len(passwordBaru) > 8 and len(passwordBaru) < 20 : + print("Password Valid") + password = passwordBaru + break + print("="*60) + print("password salah") + print("="*60) + + elif opsi == 6: + print('Sampai jumpa lagi') + break \ No newline at end of file diff --git a/H071221101/Tugas Praktikum 10/2.py b/H071221101/Tugas Praktikum 10/2.py new file mode 100644 index 0000000..00003e1 --- /dev/null +++ b/H071221101/Tugas Praktikum 10/2.py @@ -0,0 +1,154 @@ +class Kendaraan: + def __init__(self, merek, roda): + self.brand = merek + self.wheel = roda + + def setBrand(self, merek): + self.brand = merek + + def getBrand(self): + return self.brand + + def setWheel(self, roda): + self.wheel = roda + + def getWheel(self): + return self.wheel + + def remMendadak(self): + self._speed = 0 + + +class Motor(Kendaraan): + def __init__(self, merek, roda): + super().__init__(merek, roda) + self._speed = 140 + self._weight = 80 + self._price = 16000 + self.__pasengger = 2 + + def gasspol(self): + self._speed = self._speed+60 + + def setSpeed(self, kecepatan): + self._speed = kecepatan + + def getSpeed(self): + return self._speed + + def setWeight(self, berat): + self._weight = berat + + def getWeight(self): + return self._weight + + def setPenumpang(self, penumpang): + self.__pasengger = penumpang + + def getPenumpang(self): + return self.__pasengger + + def setHarga(self, harga): + self._price = harga + + def getHarga(self): + return self._price + + +class Mobil(Kendaraan): + def __init__(self, merek, roda): + super().__init__(merek, roda) + self._speed = 500 + self._weight = 300 + self._price = 200000 + self._pasengger = 5 + + def gasspol(self): + self._speed = self._speed+120 + + def setSpeed(self, kecepatan): + self._speed = kecepatan + + def getSpeed(self): + return self._speed + + def setWeight(self, berat): + self._weight = berat + + def getWeight(self): + return self._weight + + def setPenumpang(self, penumpang): + self._pasengger = penumpang + + def getPenumpang(self): + return self._pasengger + + def setHarga(self, harga): + self._price = harga + + def getHarga(self): + return self._price + + +class Matic(Motor): + def __init__(self, merek, roda): + super().__init__(merek, roda) + self._price = 20000 + + def special(self): + print(f'{self.brand}tidak perlu ganti gigi') + + +class Manual(Motor): + def __init__(self, merek, roda): + super().__init__(merek, roda) + self._weight = 60 + + def special(self): + self._speed = self._speed+20 + print(f'{self.brand} perlu ganti gigi tapi kecepatan bertambah 20 tiap ganti gigi menjadi {self._speed}') + + +class DuaKabin(Mobil): + def __init__(self, merek, roda): + super().__init__(merek, roda) + self._price = 210000 + self._speed = 600 + + def special(self): + print(f"Bisa Sat Set Sat Set waktu macet") + + +class TigaKabin(Mobil): + def __init__(self, merek, roda): + super().__init__(merek, roda) + self._price = 300000 + + def special(self): + self._pasengger = self._pasengger+3 + + +class Jual_Kendaraan: + def kondisiendaraan(self): + pass + + +class Bekas(Jual_Kendaraan): + def __init__(self) -> None: + super().__init__() + self._price = "Murah" + + +class Baru(Jual_Kendaraan): + def __init__(self) -> None: + super().__init__() + self._price = "Mahal" + + +Toyota = TigaKabin("Toyota", roda=4) +Toyota.gasspol() +Toyota.special() +print(f"kecepatan mobil toyota adalah : {Toyota.getSpeed()}") +print(f"Toyota dapat menampung {Toyota.getPenumpang()} penumpang") +print(f"harga mobil Toyota adalah {Toyota.getHarga()}000 rupiah") diff --git a/H071221101/Tugas Praktikum 6/no_1.py b/H071221101/Tugas Praktikum 6/no_1.py index 3eb556f..2cb2531 100644 --- a/H071221101/Tugas Praktikum 6/no_1.py +++ b/H071221101/Tugas Praktikum 6/no_1.py @@ -11,5 +11,5 @@ print ('Berhasil') -except : +except FileNotFoundError : print ('Gagal') \ No newline at end of file diff --git a/H071221101/Tugas Praktikum 7/no_1.py b/H071221101/Tugas Praktikum 7/no_1.py new file mode 100644 index 0000000..0a66992 --- /dev/null +++ b/H071221101/Tugas Praktikum 7/no_1.py @@ -0,0 +1,8 @@ +import re +s= input() +pola1= r"(\A([A-Z]|[0|2|4|6|8]|[a-z]){40})(\s|1|3|5|7|9){5}" +result1= re.match(pola1, s) +if result1 : + print("true") +else : + print("false") \ No newline at end of file diff --git a/H071221101/Tugas Praktikum 7/no_2.py b/H071221101/Tugas Praktikum 7/no_2.py new file mode 100644 index 0000000..0da4eea --- /dev/null +++ b/H071221101/Tugas Praktikum 7/no_2.py @@ -0,0 +1,34 @@ +import re +def match_IPv4(string): + # 250-255 200-249 100-199 0-99 + pola_0to255 = r"(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])" + pola_IPv4 = fr"{pola_0to255}"+fr".{pola_0to255}"*3 + return re.fullmatch(pola_IPv4,string) + +def match_IPv6(string): + hex_4char = r"[0-9A-Fa-f]{1,4}" + pola_IPv6 = fr"{hex_4char}"+fr":{hex_4char}"*7 + return re.fullmatch(pola_IPv6,string) + +# handling input jumlah ip address +try: + count = int(input("jumlah inputan : ")) +except: + print("error : pastikan inputan berupa bilangan positif") +else : + # jika input jumlah valid + + # minta input ip address sebanyak count + list_ip_address = [] + for i in range(count): + input_ip = input(f"masukkan ip ke{i+1} :") + list_ip_address.append(input_ip) + + # cek jenis tiap inputnya (IPv4/IPv6/None) + for ip_address in list_ip_address: + if match_IPv4(ip_address): + print("IPv4") + elif match_IPv6(ip_address): + print("IPv6") + else: + print("Bukan IP Address") \ No newline at end of file diff --git a/H071221101/Tugas Praktikum 8/no_1.py b/H071221101/Tugas Praktikum 8/no_1.py new file mode 100644 index 0000000..62a3ad2 --- /dev/null +++ b/H071221101/Tugas Praktikum 8/no_1.py @@ -0,0 +1,36 @@ +# creat class +class person: + + def __init__(self, name, age, gender, alamat): + self.name = name + self.age = age + self.gender = gender + self.alamat = alamat + + def setAge(self, age) : + self.age = age + def getAge(self): + return self.age + def setName(self, name) : + self.name = name + def getName(self): + return self.name + def setGender(self, gender) : + self.gender = gender + def getGender(self): + if self.gender == True : + return "Male" + else : + return "Female" + def setAlamat(self, alamat) : + self.alamat = alamat + def getAlamat (self) : + return self.alamat + +data = person("el", 18, False, "Isekai") +print(data.getAge()) +print(data.getName()) +print(data.getGender()) +print(data.getAlamat()) +data.setName("lisa") +print(data.getName()) \ No newline at end of file diff --git a/H071221101/Tugas Praktikum 8/no_2.py b/H071221101/Tugas Praktikum 8/no_2.py new file mode 100644 index 0000000..cc5e499 --- /dev/null +++ b/H071221101/Tugas Praktikum 8/no_2.py @@ -0,0 +1,26 @@ +lebar = float(input()) +tinggi = float(input()) +panjang = float(input()) +massa = float(input()) + +class kubus : + def __init__(self, lebar, tinggi, panjang) : + self.lebar= lebar + self.tinggi= tinggi + self.panjang= panjang + def setLebar(self, lebar) : + self.lebar= lebar + def setTinggi(self, tinggi) : + self.tinggi= tinggi + def setPanjang(self, panjang) : + self.panjang= panjang + def setMassa(self, massa) : + self.massa= massa + def getMassaJenis(self) : + return self.massa/(self.panjang*self.lebar*self.tinggi) + +kubus = kubus (lebar, tinggi, panjang) +kubus.setMassa(massa) +print("Massa Jenis =", kubus.getMassaJenis()) +kubus.setMassa(massa*2) +print("Massa Jenis =", kubus.getMassaJenis()) \ No newline at end of file diff --git a/H071221101/Tugas Praktikum 9/hero.py b/H071221101/Tugas Praktikum 9/hero.py new file mode 100644 index 0000000..be34c6b --- /dev/null +++ b/H071221101/Tugas Praktikum 9/hero.py @@ -0,0 +1,79 @@ +class Human: + def __init__(self, name, position): + self.name = name + self.__pos_x = position + + def setName(self, name): + self.name = name + def setMovement(self, move): + if move == 'L': + self.__pos_x -= self._speed + elif move == 'R': + self.__pos_x += self._speed + + def getName(self): + return self.name + def getMovement(self): + return self.__pos_x + +class Hero(Human): + def __init__(self, name, pos_x): + super().__init__(name, pos_x) + self._power = 15 + self._health = 400 + self._armor = 15 + self._speed = 3 + + def setPower(self, power): + self._power = power + def setHealth(self, health): + self._health = health + def setArmor(self, armor): + self._armor = armor + def setSpeed(self, speed): + self._speed = speed + + def attack(self, target): + target._health -= self._power + + def getPower(self): + return self._power + def getHealth(self): + return self._health + def getArmor(self): + return self._armor + 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, name, pos_x): + super().__init__(name, 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 \ No newline at end of file diff --git a/H071221101/Tugas Praktikum 9/no_1.py b/H071221101/Tugas Praktikum 9/no_1.py new file mode 100644 index 0000000..e18c13b --- /dev/null +++ b/H071221101/Tugas Praktikum 9/no_1.py @@ -0,0 +1,22 @@ +from hero import Warrior, Assassin, Support +warrior = Warrior("ganyu", pos_x=10) +assassin = Assassin("diluc", pos_x=25) +support = Support("xiangling",pos_x=30) + +# sebelum +print("health (before)", warrior.getHealth()) +assassin.attack(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())i \ No newline at end of file diff --git a/README.md b/README.md index 157641c..5593689 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -"# LABPP22" +email = "lulu_dier@gmail.com" +