# Untitled

unknown
python
2 years ago
1.5 kB
1
Indexable
Never
```
n = int(input("Masukkan banyak barang: "))

awal = [0 for i in range(n)]
diskon = [0 for i in range(n)]
dismax = 0
x = 0

for i in range(n):
awal[i] = int(input("Masukkan harga awal barang ke-"+str(i+1)+": "))

for i in range(n):
diskon[i] = int(input("Masukkan besar diskon (dalam persen) barang ke-"+str(i+1)+": "))

for i in range(n):
tmp = awal[i] * diskon[i] / 100
if tmp > dismax:
x = i
dismax = tmp

print("Barang "+str(x+1)+" memiliki diskon paling besar yaitu "+str(int(dismax))+".")

#######

n = int(input("Masukkan banyak lampu: "))
lampu = [0 for i in range(n)]

x = int(input("Masukkan berapa kali Tuan Kil menekan tombol: "))

for i in range(x):
y = int(input("Tombol yang ditekan ke "+str(i+1)+": "))
if y == 1:
lampu[0]=(lampu[0]+1)%2
lampu[1]=(lampu[1]+1)%2
elif y == n:
lampu[n-2]=(lampu[n-2]+1)%2
lampu[n-1]=(lampu[n-1]+1)%2
else:
lampu[y-2]=(lampu[y-2]+1)%2
lampu[y-1]=(lampu[y-1]+1)%2
lampu[y]=(lampu[y]+1)%2

print("Keadaan akhir rangkaian lampu adalah ", end="")
for i in range(n):
print(lampu[i],end="")
print(".")

#######

a = int(input("Masukkan panjang string 1: "))
str_a = str(input("Masukkan string 1: "))
b = int(input("Masukkan panjang string 2: "))
str_b = str(input("Masukkan string 2: "))

ans=0

for i in range(b-a+1):
sama = True
j = 0
while sama and j <a:
if str_a[j]==str_b[j+i]:
j += 1
else:
sama = False
if j == a:
ans += 1

print("String 1 muncul sebanyak",ans,"kali.")```