# kontol

unknown
python
7 months ago
3.8 kB
5
Indexable
Never
```from turtle import *

#input dari user
jarak_tower = 0 # ini fungsinya biar variabel bisa di akses secara global
beda_tinggi_tower = 0 # ini fungsinya biar variabel bisa di akses secara global
banyak_tower = int(numinput("Tower to Build", "Enter the number of towers you want to build (integer)", minval= 1 ))
if banyak_tower > 1: #biar kalo towernya cuma 1 gak butuh yang namanya jarak antar tower dan beda tinggi antar tower
jarak_tower = int(numinput("Distance between Towers", "Enter the distance between towers (integer)",minval= 2, maxval= 5))
beda_tinggi_tower = int(numinput("Tower Layer Difference", "Enter the number of layer differences between each tower (integer)",minval= 2, maxval= 5))
panjang = int(numinput("Brick Width", "Enter the width of a brick (integer)",minval= 1, maxval= 35))
tinggi = int(numinput("Brick Height", "Enter the height of a brick (integer)",minval= 1, maxval= 25))
banyak_bata = int(numinput("Layer Width", "Enter the width of the layer (integer)",minval= 1, maxval= 10))
first_layer = int(numinput("The Number of First Tower Layers","Enter the number of layers for the first tower (integer)",minval= 1))

# variabel awal
banyaknya = 0 # menghitung banyaknya batu bata yang akan dibuat
awal_x = -(banyak_bata*banyak_tower + jarak_tower*(banyak_tower-1))*panjang/2 # menggeser agar bangunan di tengah
awal_y = 0
speed(0) # kecepatan maksimal turtle

for iiii in range(banyak_tower): #membuat tower
up()
goto(awal_x,awal_y)
down()
fillcolor("#CA7F65")
for iii in range(first_layer+beda_tinggi_tower*iiii): #membuat tinggi tower
for ii in range(banyak_bata): #membuat bata satu layer
begin_fill()
banyaknya += 1
for i in range(2): #membuat bata
forward(panjang)
right(90)
forward(tinggi)
right(90)
forward(panjang)
end_fill()
up()
awal_y += tinggi
goto(awal_x,awal_y)
down()
up()
backward(panjang/2) # biar mundu sedikit
down()
fillcolor("#693424") #membuat atap tower
for ii in range(banyak_bata+1): # untuk banyak bata kepala tower selalu lebih satu dari badan
begin_fill()
banyaknya += 1 #menghitung banyak nya batu bata yang digunakan
for i in range(2):
forward(panjang)
right(90)
forward(tinggi)
right(90)
forward(panjang)
end_fill()
up()
backward(panjang/2)
backward(banyak_bata/2*panjang)
backward(panjang/2)
left(90)
down()
fillcolor("#000000") #membuat badan jamur
begin_fill()
for i in range(2):
forward(tinggi*2)
right(90)
forward(panjang)
right(90)
end_fill()
#membuat mata jamur
fillcolor("white")
up()
forward(tinggi)
right(90)
forward(panjang/3)
down()
begin_fill()
circle(panjang/8)
end_fill()
up()
forward(panjang/3)
down()
begin_fill()
circle(panjang/8)
end_fill()
up()
backward(panjang/3*2)
left(90)
forward(tinggi)
right(90)
forward(panjang+panjang/2)
left(90)
down()
#membuat kepala jamur
fillcolor("#030065")
begin_fill()
circle(panjang,180)
left(90)
forward(panjang*2)
end_fill()
# menggeser untuk membuat tower selanjutnya
up()
awal_x += (banyak_bata+jarak_tower)*panjang
awal_y = 0
down()

up()
goto(0,-100)
down()
# membuat tulisan
tulisan = str(banyak_tower) + " Super Mario Towers have been build with a total of " + str(banyaknya) +" bricks"
write(tulisan,align="center",font=("Arial","12","bold"))
exitonclick()```