Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import math
- basenums = [ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
- tensnums = [ "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"]
- modnums = ["hundred", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion","nontillion", "decillion", "undecillion", "duodecillion", "tredecillion", "quattuordecillion", "quindecillion", "sexdecillion", "septendecillion", "octodecillion", "novemdecillion", "vigintillion"]
- largest = 10**66 - 1
- def int_to_word(val):
- if val < 0:
- neg = "negative "
- val = -val
- else:
- neg = ""
- if val > largest:
- return "a very large "+neg+"number"
- if val < 20:
- return neg + basenums[val]
- if val < 100:
- tens = (val - (val % 10))
- if val - tens == 0:
- v = ""
- else:
- v = "-"+int_to_word(val - tens)
- return neg + tensnums[tens/10 - 2] + v
- if val < 1000:
- return neg + int_to_word(val / 100) + " " + modnums[0] + " " + int_to_word(val - (val/100) * 100)
- # how many thousands blocks we have
- places = int(math.floor(math.log(val, 1000)))
- # multiples of this
- between = (val) / (1000**places)
- return neg + int_to_word(between) + " " + modnums[places] + " " + int_to_word(val - between * 1000**places)
- def get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function(p_mode, p_numerical_value_equiv):
- return int_to_word(int(p_numerical_value_equiv.replace(",", "")))
- def bottles_of_beer(start=999):
- def get_bottles(amt):
- if amt == 1:
- return "bottle of beer"
- return "bottles of beer"
- w = int_to_word(start)
- print w.capitalize(), get_bottles(start), "on the wall,", w, get_bottles(start)+", take one down and pass it around,",
- for num in range(start-1, 0, -1):
- word = int_to_word(num)
- print word, get_bottles(num), "on the wall!"
- print word.capitalize(), get_bottles(num), "on the wall,", word, get_bottles(num)+", take one down and pass it around,",
- num -= 1
- print int_to_word(num), get_bottles(num), "on the wall!"
- if __name__ == "__main__":
- bottles_of_beer(32)
- print int_to_word(56)
- print int_to_word(7)
- print int_to_word(15)
- print int_to_word(532)
- print int_to_word(519)
- print int_to_word(5299)
- print int_to_word(99999)
- print int_to_word(999392)
- print int_to_word(1234561)
- print int_to_word(3345291)
- print int_to_word(333242212)
- print int_to_word(-9289234215)
- print int_to_word(2342342341235)
- print int_to_word(234324123412342352134123451432452342348328821388283475278482134234)
- print int_to_word(-23432412341234235213412345143245234234832882138828347527848213423435)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement