Advertisement
Guest User

gavin

a guest
Apr 16th, 2012
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import math
  4.  
  5. basenums = [ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
  6. tensnums = [ "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"]
  7. modnums = ["hundred", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion","nontillion", "decillion", "undecillion", "duodecillion", "tredecillion", "quattuordecillion", "quindecillion", "sexdecillion", "septendecillion", "octodecillion", "novemdecillion", "vigintillion"]
  8.  
  9. largest = 10**66 - 1
  10.  
  11. def int_to_word(val):
  12. if val < 0:
  13. neg = "negative "
  14. val = -val
  15. else:
  16. neg = ""
  17.  
  18. if val > largest:
  19. return "a very large "+neg+"number"
  20.  
  21. if val < 20:
  22. return neg + basenums[val]
  23.  
  24. if val < 100:
  25. tens = (val - (val % 10))
  26. if val - tens == 0:
  27. v = ""
  28. else:
  29. v = "-"+int_to_word(val - tens)
  30. return neg + tensnums[tens/10 - 2] + v
  31.  
  32. if val < 1000:
  33. return neg + int_to_word(val / 100) + " " + modnums[0] + " " + int_to_word(val - (val/100) * 100)
  34.  
  35. # how many thousands blocks we have
  36. places = int(math.floor(math.log(val, 1000)))
  37. # multiples of this
  38. between = (val) / (1000**places)
  39. return neg + int_to_word(between) + " " + modnums[places] + " " + int_to_word(val - between * 1000**places)
  40.  
  41.  
  42. def get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function(p_mode, p_numerical_value_equiv):
  43. return int_to_word(int(p_numerical_value_equiv.replace(",", "")))
  44.  
  45. def bottles_of_beer(start=999):
  46. def get_bottles(amt):
  47. if amt == 1:
  48. return "bottle of beer"
  49. return "bottles of beer"
  50.  
  51. w = int_to_word(start)
  52. print w.capitalize(), get_bottles(start), "on the wall,", w, get_bottles(start)+", take one down and pass it around,",
  53.  
  54. for num in range(start-1, 0, -1):
  55. word = int_to_word(num)
  56.  
  57. print word, get_bottles(num), "on the wall!"
  58. print word.capitalize(), get_bottles(num), "on the wall,", word, get_bottles(num)+", take one down and pass it around,",
  59.  
  60. num -= 1
  61. print int_to_word(num), get_bottles(num), "on the wall!"
  62.  
  63. if __name__ == "__main__":
  64. bottles_of_beer(32)
  65.  
  66. print int_to_word(56)
  67. print int_to_word(7)
  68. print int_to_word(15)
  69. print int_to_word(532)
  70. print int_to_word(519)
  71. print int_to_word(5299)
  72. print int_to_word(99999)
  73. print int_to_word(999392)
  74. print int_to_word(1234561)
  75. print int_to_word(3345291)
  76. print int_to_word(333242212)
  77. print int_to_word(-9289234215)
  78. print int_to_word(2342342341235)
  79. print int_to_word(234324123412342352134123451432452342348328821388283475278482134234)
  80. print int_to_word(-23432412341234235213412345143245234234832882138828347527848213423435)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement