Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@galihboy
Created October 12, 2021 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galihboy/30857272df488f66c3d8f14093a989e2 to your computer and use it in GitHub Desktop.
Save galihboy/30857272df488f66c3d8f14093a989e2 to your computer and use it in GitHub Desktop.
menulis bilangan versi 2
"""
@author: galih-hermawan
"""
# fungsi untuk menyesuaikan kata dalam kamus Alias
def KalimatBaru(kalimat):
lstKalimat = kalimat.split()
lstKalimat = [kamusAlias[x] if x in kamusAlias else x for x in lstKalimat]
kalimatBaru = " ".join(lstKalimat)
#lstKalimatBaru = kalimatBaru.split()
return kalimatBaru
# tambahkan ketiga kamus yang sudah dibuat sebelumnya di sini.
# kamusAngka
# kamusSatuan
# kamusAlias
kalimat = "seratus tujuh belas ribu"
kalimat = KalimatBaru(kalimat)
lstKalimat = kalimat.split()
ukuran = len(lstKalimat)
teks = ""
for i, sat in enumerate(lstKalimat):
if sat in kamusAngka:
teks += "+" + kamusAngka[sat]
elif sat == "belas":
teks = teks[:-1] + "1" + teks[-1:]
elif sat in kamusSatuan:
pengali = 10**kamusSatuan[sat]
if i == ukuran-1:
teks = "(" + teks[:] + ")" + "*" + str(pengali)
else:
teks += "*" + str(pengali)
print("Ekspresi: ", teks)
print("Hasil evaluasi: ", eval(teks))
# Ekspresi: (+1*100+17)*1000
# Hasil evaluasi: 117000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment