Fakultas Ilmu Komputer UI

Commit de9611d1 authored by Ruly Achmad Gemilang Gultom's avatar Ruly Achmad Gemilang Gultom
Browse files

Tugas Pemrograman Ekstra Soal 1 - 1906399915

parent 7c34b852
import urllib.request
from random import randint
def cari_nilai(pilihan,kesulitan):
page = urllib.request.urlopen("https://baguspribadi99.github.io/difficulty/difficulty.html")
text = page.read().decode("utf8")
sebelum = text.find(kesulitan)
cari_li = text.find('</li>',text.find(pilihan,sebelum))
return int(text[text.find(pilihan,sebelum)+len(pilihan+': '):cari_li])
kesulitan = input("masukkan tingkat kesulitan yang diinginkan:").lower()
hp_student = cari_nilai('hp-student',kesulitan)
hp_kuliah = cari_nilai('kuliah',kesulitan)
attack_student = cari_nilai('attack-student',kesulitan)
attack_kuliah = cari_nilai('attack-kuliah',kesulitan)
print("Berikut atribut objek :")
print("- Student, HP =",hp_student,"attack =",attack_student)
print("- Kuliah, HP =",hp_kuliah,"attack =",attack_kuliah)
while hp_student>0 or hp_kuliah>0 :
if hp_student >0:
jawaban = True
while jawaban == True:
action = input("Masukkan action untuk student!! :").lower()
if action == 'serang':
hp_kuliah-= attack_student
print("Student mengerjakan tugas, HP kuliah berkurang sebanyak",attack_student)
jawaban = False
elif action == 'istirahat':
hp_student = 100
print("Student istirahat, HP student pulih kembali")
jawaban = False
else:
print(action,"tidak termasuk kedalam pilihan.(serang atau istirahat)")
jawaban == True
else:
print("Sayang sekali anda telah dimakan oleh beratnya tugas kuliah!")
hp_kuliah=0
if hp_kuliah>0:
serangan = randint(0,1)
if serangan == 0:
hp_student-= attack_kuliah
print("Deadline menghantui student, HP student berkurang sebanyak",attack_kuliah)
elif serangan == 1:
hp_kuliah += attack_kuliah
print("Ada revisi, HP kuliah bertambah sebanyak",attack_kuliah)
else:
print(action,"tidak termasuk kedalam pilihan.(serang atau bertahan")
else:
print("Selamat anda telah mengalahkan tugas-tugas kuliah!")
hp_student=0
import urllib.request
from random import randint
def cari_nilai(pilihan,kesulitan):
page = urllib.request.urlopen("https://baguspribadi99.github.io/difficulty/difficulty.html")
print("Sayang sekali anda telah dimakan oleh beratnya tugas kuliah!")
hp_kuliah=0
if hp_kuliah>0:
jawaban = True
while jawaban== True:
action = input("Masukkan action untuk kuliah!! :").lower()
if action == 'serang':
hp_student-= attack_kuliah
print("Deadline menghantui student, HP student berkurang sebanyak",attack_kuliah)
jawaban = False
elif action == 'bertahan':
hp_kuliah += attack_kuliah
print("Ada revisi, HP kuliah bertambah sebanyak",attack_kuliah)
jawaban = False
else:
print(action,"tidak termasuk kedalam pilihan.(serang atau bertahan")
jawaban == True
serangan = randint(0,1)
if serangan == 0:
hp_student-= attack_kuliah
print("Deadline menghantui student, HP student berkurang sebanyak",attack_kuliah)
elif serangan == 1:
hp_kuliah += attack_kuliah
print("Ada revisi, HP kuliah bertambah sebanyak",attack_kuliah)
else:
print(action,"tidak termasuk kedalam pilihan.(serang atau bertahan")
else:
print("Selamat anda telah mengalahkan tugas-tugas kuliah!")
hp_student=0
import urllib.request
import urllib.parse
def ambil_info_stok():
page = urllib.request.urlopen('https://ceritanyatuwiter.herokuapp.com/1806197304')
text = page.read().decode('utf8')
where = text.find('Stok Terkini: ')
awal = where + len('Stok Terkini: ') ; akhir = text.find('</p>')
stok = int(text[awal:akhir])
return(stok)
def laporkan_stok():
stok_sekarang = str(stok - disalurkan)
param = urllib.parse.urlencode({"pesan": "Stok Terkini: "+stok_sekarang})
resp = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1806197304/lapor", param.encode())
def request_stok():
param = urllib.parse.urlencode({"pesan": "@burhan request restock untuk saya"})
resp = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1806197304/lapor", param.encode())
stok = ambil_info_stok()
disalurkan = 1
while disalurkan > 0:
disalurkan = int(input('Berapa jumlah tabung yang ingin disalurkan: '))
if disalurkan > 0:
if (stok-disalurkan) == 0:
print(f'Penyaluran {disalurkan} tabung berhasil, sekarang tersisa 0')
request_stok()
elif disalurkan > stok:
print('Stok tidak cukup')
request_stok()
else:
print(f'Penyaluran {disalurkan} tabung berhasil, sekarang tersisa {stok - disalurkan}')
laporkan_stok()
stok = ambil_info_stok()
import urllib.request
import urllib.parse
page = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915")
text = page.read().decode("utf8")
print(text)
disalurkan = 1
#stok_sekarang =
#laporkan_stok =
stok = ambil_info_stok()
def laporkan_stok():
param = urllib.parse.urlencode({"pesan":"Stok Terkini: stok_sekarang"})
resp = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915/lapor",param.encode())
def ambil_info_stok():
while stok >0 and disalurkan > 0:
disalurkan = input("masukkan jumlah tabung yang disalurkan: ")
if disalurkan > 0:
if disalurkan > stok:
print("stok tidak cukup")
else:
print("penyaluran jumlah disalurkan tabung berhasil. sekarang tersisa stok - disalurkan")
laporkan_stok(stok - disalurkan)
stok = ambil_info_stok()
\ No newline at end of file
import urllib.request
page = urllib.request.urlopen("https://baguspribadi99.github.io/difficulty/difficulty.html")
text = page.read().decode("utf8")
difficulty = input("tingkat kesulitan permainan: ")
indeks_sebelum = text.find(difficulty)
indeks_hp_student = text.find("hp-student", indeks_sebelum)
hp_student = text[indeks_hp_student + 12 : text.find("</li>",indeks_hp_student)]
indeks_hp_kuliah = text.find("hp-kuliah", indeks_sebelum)
hp_kuliah = text[indeks_hp_kuliah + 12:text.find("</li>",indeks_hp_kuliah)]
indeks_attack_student = text.find("attack-student", indeks_sebelum)
attack_student = text[indeks_attack_student + 12 : text.find("</li>",indeks_attack_student)]
indeks_attack_kuliah = text.find("attack-kuliah", indeks_sebelum)
attack_kuliah = text[indeks_attack_kuliah + 12 : text.find("</li>",indeks_attack_kuliah)]
while hp_student > 0 or hp_kuliah > 0:
action_student = input("action untuk student: ")
if action_student == 'serang':
hp_kuliah -= hp_student
print("student mengerjakan tugas, hp kuliah berkurang sebanyak {}".format(attack_student))
elif action == 'istirahat' :
hp_student == 100
print("Student Istirahat, hp Student pulih kembali")
action_kuliah = input("masukkan action untuk kuliah: ")
if action_kuliah == 'serang':
hp_student -= attack_kuliah
print("Deadline menghantui student, hp student berkurang sebanyak {} ".format(attack_kuliah))
elif action_kuliah == 'bertahan' :
hp_kuliah -= attack_kuliah
print("ada revisi, {} bertambah sebanyak {}".format(hp_kuliah,attack_kuliah))
try:
a = int(input("masukkan bilangan pertama: "))
b = int(input("masukkan bilangan kedua: "))
c = int(input("masukkan bilangan ketiga: "))
lis = [a,b,c]
lis.sort()
print(lis)
d = a**2
e = b**2
f = c**2
g = (d+e)**0.5
h = (d+f)**0.5
i = (d+g)**0.5
j = (e+f)**0.5
k = (e+g)**0.5
l = (f+g)**0.5
a1 = (d-e)**0.5
a2 = (d-f)**0.5
a3 = (d-g)**0.5
a4 = (e-f)**0.5
a5 = (e-g)**0.5
a6 = (f-g)**0.5
#samasisi
if a == b == c:
print("segitiga sama sisi")
#samakaki
elif a == b or a == c or b == c:
print("segitiga samakaki")
#Siku-siku
elif g == a or g == b or g == c or a1 == a or a1 == b or a1 == c:
print("segitiga siku2")
elif h == a or h == b or h == c or a2 == a or a2 == b or a2 == c:
print("segitiga siku2")
elif i == a or i == b or i == c or a3 == a or a3 == b or a3 == c:
print("segitiga siku2")
elif j == a or j == b or j == c or a4 == a or a4 == b or a4 == c:
print("segitiga siku2")
elif k == a or k == b or k == c or a5 == a or a5 == b or a5 == c:
print("segitiga siku2")
elif l == a or l == b or l == c or a6 == a or a6 == b or a6 == c:
print("segitiga siku2")
#bukan segitiga
elif lis[0] + lis[1] <= lis[2]:
print("bukan segitiga")
else:
print("segitiga sembarang")
except ValueError:
print("input bukan angka")
\ No newline at end of file
import urllib.request
def get_data(datas):
try:
data = urllib.request.urlopen(datas)
text = data.read().decode("utf8")
return text
except urllib.error.HTTPError:
print("Link Tidak Ditemukan!")
datas1 = "https://pudyprima.github.io/covid19-jakarta"
#memanggil fungsi get_data()
print(get_data("https://pudyprima.github.io/covid19-indonesia"))
def get_data_per_wilayah(wilayah):
awal = get_data(datas1).lower()
wilayah = wilayah.lower()
ai = awal.find("<td>"+ str(wilayah) +"</td>")
if ai != -1:
lu = awal.find("<td>",ai+3)
le = awal[lu+4:lu+7]
return le
else:
f = "kota tidak Ditemukan!"
return f
#memanggil fungsi get_data_per_wilayah
print(get_data_per_wilayah("Jakarta Barat"))
def get_data_jakarta():
p = int(get_data_per_wilayah("Jakarta Barat"))
q = int(get_data_per_wilayah("Jakarta Timur"))
r = int(get_data_per_wilayah("Jakarta Pusat"))
s = int(get_data_per_wilayah("Jakarta Selatan"))
t = int(get_data_per_wilayah("Jakarta Utara"))
tambah = p+q+r+s+t
return tambah
#memanggil fungsi get_data_jakarta
print(get_data_jakarta())
def get_total_kasus_by_keyword(keyword):
try:
global datas1
datas1 = "https://pudyprima.github.io/covid19-indonesia"
keyword = keyword.lower()
datak = str(get_data(datas1))
datakk = datak.lower()
counter = datakk.count(keyword)
return counter
except TypeError or AttributeError:
nono = "Bukan jenis Keyword! silahkan input kembali"
return nono
#memanggil fungsi get_total_kasus_by_keyword
print(get_total_kasus_by_keyword("jawa tengah"))
\ No newline at end of file
try:
a = int(input("masukkan bilangan pertama: "))
b = int(input("masukkan bilangan kedua: "))
c = int(input("masukkan bilangan ketiga: "))
lis = [a,b,c]
lis.sort()
print(lis)
d = a**2
e = b**2
f = c**2
g = (d+e)**0.5
h = (d+f)**0.5
i = (d+g)**0.5
j = (e+f)**0.5
k = (e+g)**0.5
l = (f+g)**0.5
a1 = (d-e)**0.5
a2 = (d-f)**0.5
a3 = (d-g)**0.5
a4 = (e-f)**0.5
a5 = (e-g)**0.5
a6 = (f-g)**0.5
#samasisi
if a == b == c:
print("segitiga sama sisi")
#samakaki
elif a == b or a == c or b == c:
print("segitiga samakaki")
#Siku-siku
elif g == a or g == b or g == c or a1 == a or a1 == b or a1 == c:
print("segitiga siku2")
elif h == a or h == b or h == c or a2 == a or a2 == b or a2 == c:
print("segitiga siku2")
elif i == a or i == b or i == c or a3 == a or a3 == b or a3 == c:
print("segitiga siku2")
elif j == a or j == b or j == c or a4 == a or a4 == b or a4 == c:
print("segitiga siku2")
elif k == a or k == b or k == c or a5 == a or a5 == b or a5 == c:
print("segitiga siku2")
elif l == a or l == b or l == c or a6 == a or a6 == b or a6 == c:
print("segitiga siku2")
#bukan segitiga
elif lis[0] + lis[1] <= lis[2]:
print("bukan segitiga")
else:
print("segitiga sembarang")
except ValueError:
print("input bukan angka")
\ No newline at end of file
import urllib.request
data = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915")
text = data.read().decode("utf8")
data2 = urllib.request.urlopen("https://pudyprima.github.io/prices.html")
text2 = data2.read().decode("utf8")
perintah = input("masukan status: ")
def lapor(stok_barang):
par = urllib.parse.urlencode({"pesan":"STATUS" + str(stok_barang)})
respon = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915/updatestatus",par.encode())
return respon
lapor(perintah)
import urllib.request
jawaban = input("input : ")
def starbuzz(x):
x = str(x)
global text2
if x == 'Y':
text = text2
dimana = text.find(">$")
start = dimana + 2
end = start + 4
textprice = text[start:end]
par = urllib.parse.urlencode({"pesan":"MAU LIHAT? :"+ str(x)})
par2 = urllib.parse.urlencode({"pesan":"NIH HARGANYA : "+ str(textprice)})
respon = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915/lapor", par.encode())
respon2 = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915/lapor", par2.encode())
else:
print("????")
return respon,respon2
starbuzz(jawaban)
\ No newline at end of file
def FPB(x, y):
x = int(x)
y = int(y)
while y:
x,y = y,x%y
return x
x = input("masukkan angka X: ")
y = input("masukkan angka Y: ")
print(FPB(x, y))
\ No newline at end of file
def FPB(x, y):
x = int(x)
y = int(y)
while y:
x,y = y,x%y
return x
x = input("masukkan angka X: ")
y = input("masukkan angka Y: ")
if FPB(x,y) == 1:
print((x,y), "adalah bilangan relatif prima")
else:
print((x,y), "bukan bilangan relatif prima")
\ No newline at end of file
def cetak_bingkai(panjang, lebar):
print("*" * panjang)
for i in range(lebar - 2):
print("*" + " " * (panjang - 2) + "*")
print("*" * panjang)
cetak_bingkai(6,4)
\ No newline at end of file
import urllib.request
data = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915")
text = data.read().decode("utf8")
data2 = urllib.request.urlopen("https://pudyprima.github.io/prices.html")
text2 = data2.read().decode("utf8")
perintah = input("masukan status: ")
def lapor(stok_barang):
par = urllib.parse.urlencode({"pesan":"STATUS" + str(stok_barang)})
respon = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915/updatestatus",par.encode())
return respon
lapor(perintah)
jawaban = input("input : ")
def starbuzz(x):
x = str(x)
global text2
if x == 'Y':
text = text2
dimana = text.find(">$")
start = dimana + 2
end = start + 4
textprice = text[start:end]
par = urllib.parse.urlencode({"pesan":"MAU LIHAT? :"+ str(x)})
par2 = urllib.parse.urlencode({"pesan":"NIH HARGANYA : "+ str(textprice)})
respon = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915/lapor", par.encode())
respon2 = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915/lapor", par2.encode())
else:
print("????")
return respon,respon2
starbuzz(jawaban)
\ No newline at end of file
import urllib.request
data = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915")
text = data.read().decode("utf8")
data2 = urllib.request.urlopen("https://pudyprima.github.io/prices.html")
text2 = data2.read().decode("utf8")
perintah = input("masukan status: ")
def lapor(stok_barang):
par = urllib.parse.urlencode({"pesan":"STATUS" + str(stok_barang)})
respon = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915/updatestatus",par.encode())
return respon
lapor(perintah)
import urllib.request
jawaban = input("input : ")
def starbuzz(x):
x = str(x)
global text2
if x == 'Y':
text = text2
dimana = text.find(">$")
start = dimana + 2
end = start + 4
textprice = text[start:end]
par = urllib.parse.urlencode({"pesan":"MAU LIHAT? :"+ str(x)})
par2 = urllib.parse.urlencode({"pesan":"NIH HARGANYA : "+ str(textprice)})
respon = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915/lapor", par.encode())
respon2 = urllib.request.urlopen("https://ceritanyatuwiter.herokuapp.com/1906399915/lapor", par2.encode())
else:
print("????")
return respon,respon2
starbuzz(jawaban)
\ No newline at end of file
def FPB(x, y):
x = int(x)
y = int(y)
while y:
x,y = y,x%y
return x
x = input("masukkan angka X: ")
y = input("masukkan angka Y: ")
print(FPB(x, y))
\ No newline at end of file
def FPB(x, y):
x = int(x)
y = int(y)
while y:
x,y = y,x%y
return x
x = input("masukkan angka X: ")
y = input("masukkan angka Y: ")
if FPB(x,y) == 1:
print((x,y), "adalah bilangan relatif prima")
else:
print((x,y), "bukan bilangan relatif prima")
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment