Skip to content

Instantly share code, notes, and snippets.

@galihboy
Created October 11, 2021 13:10
Show Gist options
  • Save galihboy/fc0ede8e4e0973c225d6cb244854cc48 to your computer and use it in GitHub Desktop.
Save galihboy/fc0ede8e4e0973c225d6cb244854cc48 to your computer and use it in GitHub Desktop.
baca bilangan versi 2
"""
@author: galih-hermawan
"""
listLabelAngka = ('nol', 'satu', 'dua', 'tiga', 'empat', 'lima', 'enam', 'tujuh', 'delapan', 'sembilan')
angka = 19
if angka < 10:
print(listLabelAngka[angka])
else:
angkaDepan = angka // 10
satuan = "puluh"
angkaSatuan = angka % 10
# pengecekan angka sepuluh dan kelompok belasan (11 s/d 19)
if angkaDepan == 1:
satuan = "belas"
if angkaSatuan == 0:
teks = "sepuluh"
elif angkaSatuan == 1:
teks = "se" + satuan
else:
teks = listLabelAngka[angkaSatuan] + " belas"
# pengecekan angka berakhiran nol
elif angkaSatuan == 0:
teks = listLabelAngka[angkaDepan] + " " + satuan
# teks dengan angka normal
else:
teks = listLabelAngka[angkaDepan] + " " + satuan + " " + listLabelAngka[angkaSatuan]
print(teks)
# output: sembilan belas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment