Skip to content

Instantly share code, notes, and snippets.

@arwankhoiruddin
Created September 5, 2017 13:19
Show Gist options
  • Save arwankhoiruddin/81795c97c32c2bbf088aa4fdbe7c81a6 to your computer and use it in GitHub Desktop.
Save arwankhoiruddin/81795c97c32c2bbf088aa4fdbe7c81a6 to your computer and use it in GitHub Desktop.
Kode python untuk membuat soal matematika sederhana (tambah, kurang, bagi, dan kali)
import random
for i in range(10):
a = random.randint(1, 4)
b = random.randint(1, 100)
c = random.randint(1, 100)
if a == 1: # tambah
print (str(i+1) + '. ' + str(b) + ' + ' + str(c))
elif a == 2: # kurang
c = b + random.randint(1, 100)
print (str(i+1) + '. ' + str(c) + ' - ' + str(b))
elif a == 3: # kali
print (str(i+1) + '. ' + str(random.randint(0,10)) + ' x ' + str(random.randint(0,10)))
elif a == 4: # bagi
c = random.randint(1,10)
b = random.randint(1,10)*c
print (str(i+1) + '. ' + str(b) + ' / ' + str(c))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment