Halaman

Selasa, 18 Maret 2025

Python - membuat soal SPLDV - beserta jawaban

 import random

a1 = 1

a2 = 2

b1 = 1

b2 = 2


def rdmKoef():

    return random.randint(1, 5)


def rdmSoal():

    return random.randint(1, 10)


while a1/a2== b1/b2 :

    x = rdmSoal()

    y = rdmSoal()

    a1 = rdmKoef()

    b1 = rdmKoef()

    a2 = rdmKoef()

    b2 = rdmKoef()


    c1 = a1*x + b1*y

    c2 = a2*x + b2*y


if a1==1: strA1 = "x"

else: strA1 = str(a1)+"x"

if b1==1: strB1 = "y"

else: strB1 = str(b1)+"y"

if a2==1: strA2 = "x"

else: strA2 = str(a2)+"x"

if b2==1: strB2 = "y"

else: strB2 = str(b2)+"y"


pers1 = strA1+" + "+strB1+" = "+str(c1)

pers2 = strA2+" + "+strB2+" = "+str(c2)

jawab = "x = "+str(x)+" dan y = "+str(y)


print(pers1)

print(pers2)

print(jawab)







Tidak ada komentar:

Posting Komentar