Created
October 12, 2021 16:40
-
-
Save galihboy/4ded23fcd4ff4f61e68704854d8b4560 to your computer and use it in GitHub Desktop.
menulis bilangan versi 1
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
# tambahkan (untuk sementara cukup) dua kamus yang sudah dibuat sebelumnya di sini. | |
# kamusAngka | |
# kamusSatuan | |
kalimat = "dua puluh" | |
lstKalimat = kalimat.split() | |
teks = "" | |
for i, sat in enumerate(lstKalimat): | |
if sat in kamusAngka: | |
teks += kamusAngka[sat] | |
elif sat in kamusSatuan: | |
pengali = 10**kamusSatuan[sat] | |
teks += "*" + str(pengali) | |
print("Ekspresi: ", teks) # output: "Ekspresi: 2*10" | |
print("Hasil evaluasi: ", eval(teks)) # output: "Hasil evaluasi: 20" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment