Created
October 12, 2021 17:38
-
-
Save galihboy/30857272df488f66c3d8f14093a989e2 to your computer and use it in GitHub Desktop.
menulis bilangan versi 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@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