Last active
August 29, 2015 14:16
-
-
Save syafdia/41e63fee01c7eabc3de3 to your computer and use it in GitHub Desktop.
Menghitung dari 1 - 999
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
#------------------------------------------------------------------------------- | |
# Name: module1 | |
# Purpose: | |
# | |
# Author: DELL | |
# | |
# Created: 26/02/2015 | |
# Copyright: (c) DELL 2015 | |
# Licence: <your licence> | |
#------------------------------------------------------------------------------- | |
def getSatuan(num): | |
words = ['satu', 'dua', 'tiga', 'empat', 'lima', 'enam', 'tujuh', 'delapan', 'sembilan'] | |
return words[int(num)-1] | |
def getPuluhan(num): | |
words = ['se', 'puluh', 'belas'] | |
data = list(num) | |
if((data[0] == '1') & (data[1] == '1')): | |
out_1 = words[0] | |
out_2 = words[2] | |
output = out_1+out_2 | |
elif((data[0] == '1') & (data[1] == '0')): | |
out_1 = words[0] | |
out_2 = words[1] | |
output = out_1+out_2 | |
elif((data[0] == '1') & (data[1] != '1')): | |
out_1 = getSatuan(data[1]) | |
out_2 = words[2] | |
output = out_1+' '+out_2 | |
elif(data[1] == '0'): | |
out_1 = getSatuan(data[0]) | |
out_2 = words[1] | |
output = out_1+' '+out_2 | |
else: | |
out_1 = getSatuan(data[0]) | |
out_2 = getSatuan(data[1]) | |
output = out_1+' '+words[1]+' '+out_2 | |
return output | |
def getRatusan(num): | |
words = ['se','ratus'] | |
data = list(num) | |
if((data[0] == '1') & (data[1] == '0') & (data[2] == '0')): | |
out_1 = words[0] | |
out_2 = words[1] | |
output = out_1+out_2 | |
elif((data[0] == '1') & (data[1] == '0') & (data[2] != '0')): | |
out_1 = words[0] | |
out_2 = words[1] | |
out_3 = getSatuan(data[2]) | |
output = out_1+out_2+' '+out_3 | |
elif((data[0] == '1') & (data[1] != '0')): | |
out_1 = words[0] | |
out_2 = words[1] | |
out_3 = getPuluhan(data[1]+data[2]) | |
output = out_1+out_2+' '+out_3 | |
elif((data[0] != '1') & (data[1] == '0') & (data[2] == '0')): | |
out_1 = getSatuan(data[0]) | |
out_2 = words[1] | |
output = out_1+" "+out_2 | |
elif((data[0] != '1')& (data[1] == '0') & (data[2] != '0')): | |
out_1 = getSatuan(data[0]) | |
out_2 = words[1] | |
out_3 = getSatuan(data[2]) | |
output = out_1+' '+out_2+' '+out_3 | |
else: | |
out_1 = getSatuan(data[0]) | |
out_2 = words[1] | |
out_3 = getPuluhan(data[1]+data[2]) | |
output = out_1+' '+out_2+' '+out_3 | |
return output | |
def terbilang(num): | |
data = list(num) | |
if(len(data) == 1): | |
return getSatuan(num) | |
elif(len(data) == 2): | |
return getPuluhan(num) | |
else: | |
return getRatusan(num) | |
def main(): | |
for i in range(999): | |
data = str(i+1) | |
print terbilang(data) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment