Fakultas Ilmu Komputer UI

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

reupload

parent de9611d1
angka = (input("masukkan angka: "))
cek_angka = int(angka)
pangkat = 0
kelipatan_dua = True
while cek_angka != 1 and kelipatan_dua:
if cek_angka % 2 == 1:
kelipatan_dua = False
else:
cek_angka /= 2
pangkat += 1
else:
if kelipatan_dua == True:
print(angka,"merupakan 2^",pangkat)
else:
print(angka,"bukan bilangan pangkat")
\ No newline at end of file
angka = int(input("masukkan angka: "))
pembagi = 0
for i in range(1,angka+1):
if angka % i == 0:
pembagi += 1
if pembagi == 2 and angka > 1:
print("bilangan ini prima")
else:
print("bilangan ini bukan prima")
\ No newline at end of file
namaAgen = input("masukkan nama agen: ")
while namaAgen != "selesai":
if namaAgen[:8] == "Koperasi":
print(namaAgen,"boleh menjadi agen LPG")
elif namaAgen[:3] == "PT.":
print(namaAgen,"Boleh menjadi agen LPG")
else:
print(namaAgen,"tidak boleh menjadi agen LPG")
namaAgen = input("masukkan nama agen: ")
print("selesai!")
\ No newline at end of file
import urllib.request
page = urllib.request.urlopen("https://skycruiser8.github.io/PF1Demo/")
datas = page.read().decode("utf8")
datas = datas.split("\n")
index = 0
while index < len(datas)-1:
nama_agen = datas[index]
permintaan_kuota = int(datas[index+1])
if nama_agen[:8] == "Koperasi":
tipe_perusahaan = "koperasi"
kuota_maks = 15000
else:
tipe_perusahaan = "PT."
kuota_maks = 20000
if permintaan_kuota > kuota_maks:
print(nama_agen," melebihi kuota maks", kuota_maks,"tabung")
else:
if permintaan_kuota > 0.75*kuota_maks:
print(nama_agen," adalah agen",tipe_perusahaan," Kelas I")
else:
if permintaan_kuota > 0.5*kuota_maks:
print(nama_agen,"adalah agen",tipe_perusahaan," kelas J")
else:
print(nama_agen,"adalah agen",tipe_perusahaan," kelas K")
index = index+2
namaAgen = input("masukkan nama agen: ")
while namaAgen != "selesai":
if namaAgen.startswith("Koperasi"):
print(namaAgen,"boleh menjadi agen LPG")
elif namaAgen.startswith("PT."):
print(namaAgen,"Boleh menjadi agen LPG")
else:
print(namaAgen,"tidak boleh menjadi agen LPG")
namaAgen = input("masukkan nama agen: ")
print("selesai!")
\ No newline at end of file
import urllib.request
page = urllib.request.urlopen("https://stevensim226.github.io/TP4/jadwal")
text = page.read().decode("utf8")
japi = text.split("<tr>")
lows = text.lower()
japi2 = lows.split("<tr>")
print("Selamat Datang di jadwal-manager!")
print("Silahkan pilih perintah = jadwal, detail, exit")
perintah = " "
while perintah != "exit":
perintah = input("masukkan perintah: ")
if perintah == "jadwal":
for i in japi:
finder = i.find('<td class="mata-kuliah">')
if finder != -1:
a = i.find(">")
b = i.find("</td>")
print(i[a+1:b])
elif perintah == "detail":
matkul = input("mata kuliah apa yang ingin anda lihat detail?: ")
matkul2 = matkul.lower()
for i in japi2:
if matkul2 in i:
p = i.find('<td class="waktu">')
q = i.find('</td>\n <td class="ruangan">')
r = i.find('<td class="ruangan">')
s = i.find('</td>\n </tr>\n')
jam = i[p+18:q]
listjam = jam.split()
listjam = listjam[1:]
startjam, mulaimenit = listjam[0].split(':')
startjam = int(startjam)
mulaimenit = int(mulaimenit)
endjam, akhirmenit = listjam[2].split(':')
endjam = int(endjam)
akhirmenit = int(akhirmenit)
print("nama mata kuliah: {}".format(matkul.title()))
print("diadakan pada setiap: {}".format(jam))
print("diadakan di ruangan: {}".format(i[q+38:s]))
print("berlangsung selama: {} jam {} menit".format(endjam-startjam, akhirmenit-mulaimenit))
else:
print("perintah tidak ditemukan, pastikan input anda benar!")
print("terimakasih sudah menggunakan jadwal manager!")
\ No newline at end of file
import urllib.request
page = urllib.request.urlopen("https://stevensim226.github.io/TP4/statistics")
text = page.read().decode("utf8")
first_li_pos = 0
first_li_close_pos = 0
kucing = 0
kuliah = 0
mahasiswa = 0
kantin = 0
kos = 0
tugas = 0
tidakDitemukan = 0
hastag_tidakDitemukan = ""
while text.find("<li>",first_li_pos+1) and text.find("</li>",first_li_close_pos+1) != -1:
open_li = text.find("<li>",first_li_pos+1)
close_li = text.find("</li",first_li_close_pos+1)
found = False
if "kucing" in text[open_li+4:close_li].lower():
kucing += 1
found = True
elif "kuliah" in text[open_li+4:close_li].lower():
kuliah += 1
found = True
elif "mahasiswa" in text[open_li+4:close_li].lower():
mahasiswa += 1
found = True
elif "kantin" in text[open_li+4:close_li].lower():
kantin += 1
found = True
elif "kos" in text[open_li+4:close_li].lower():
kos += 1
found = True
elif "tugas" in text[open_li+4:close_li].lower():
tugas += 1
found = True
elif not found:
tidakDitemukan += 1
hastag_tidakDitemukan += text[open_li+4:close_li] + " "
first_li_pos = open_li
first_li_close_pos = close_li
print("terdapat {} post untuk hashtag kucing".format(kucing))
print("terdapat {} post untuk hashtag kuliah".format(kuliah))
print("terdapat {} post untuk hashtag mahasiswa".format(mahasiswa))
print("terdapat {} post untuk hashtag kantin".format(kantin))
print("terdapat {} post untuk hashtag kos".format(kos))
print("terdapat {} post untuk hashtag tugas".format(tugas))
print("terdapat {} post untuk dengan hashtag tidak terklasifikasi".format(tidakDitemukan))
print("dengan hashtag: {}".format(hastag_tidakDitemukan))
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: