Contoh Soal Pemrograman – Pola Segitiga Siku-siku

Pemrograman Python

Pada posting sebelumnya sudah dicontohkan soal pemrograman dalam bahasa Python. Kali ini, akan ditampilkan lagi contoh berikutnya.

Soal:
Buatlah program Python untuk menampilkan pola segitiga siku-siku menggunakan forin.

Jawab:

Pola 1

*  *  *  *  *  *
*  *  *  *  *
*  *  *  *
*  *  *
*  *
*

Jawab:

siku_siku_1.py
tinggi = 6

for baris in range(0, tinggi):
    for kolom in range(0, tinggi-baris):
        print("*", end=" ")
    print("")

 

Pola 2

*
*  *
*  *  *
*  *  *  *
*  *  *  *  *
*  *  *  *  *  *

Jawab:

siku_siku_2.py
tinggi = 6

for baris in range(0, tinggi):
    for kolom in range(0, baris+1):
        print("*", end=" ")
    print("")

Pola 3

               *
            *  *
         *  *  *
      *  *  *  *
   *  *  *  *  *
*  *  *  *  *  *

Jawab:

siku_siku_3.py
tinggi = 6

for baris in range(0, tinggi):
    for kolom in range(1, tinggi-baris):
        print(" ", end=" ")
    for bintang in range(0, baris+1):
        print("*", end=" ")
    print("")

Demikian contoh pola segitiga dalam pemrograman Python. Semoga bermanfaat.

49,917 thoughts on “Contoh Soal Pemrograman – Pola Segitiga Siku-siku

  1. Fіrst ߋff Ι want to ѕay fantastic blog! I hɑd ɑ qquick question ᴡhich І’ɗ ljke to ask
    іf you doo not mind.Ι ѡas interеsted to кnow hоw
    you center yourself and cleɑr уⲟur head prior tο writing.

    І’ᴠe had a һard time clearing my thoսghts in getting
    my thoubhts out. Ι do enjoy writing howeᴠer іt ϳust seem like tһe fіrst 10
    to 15 minutes are lost just trying tο figure ᧐ut how to beɡin. Any suggestions ᧐r tips?
    Τhank уou!

    my site – lire plus d’informations

Leave a Reply

Your email address will not be published.