Skip to content

Instantly share code, notes, and snippets.

@zoeisnowooze
Created April 4, 2023 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoeisnowooze/687286f6b85e48f7dbd9d4d054499cf4 to your computer and use it in GitHub Desktop.
Save zoeisnowooze/687286f6b85e48f7dbd9d4d054499cf4 to your computer and use it in GitHub Desktop.
import os
def words(n):
if n >= 1000:
return words(n // 1000) + " thousand " + words(n % 1000)
elif n >= 100:
return words(n // 100) + " hundred " + words(n % 100)
elif n >= 20:
tens = [
"twenty",
"thirty",
"fourty",
"fifty",
"sixty",
"seventy",
"eighty",
"ninety",
][n // 10 - 2]
if n % 10 == 0:
return tens
else:
return tens + "-" + words(n % 10)
else:
return [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen",
][n]
def main():
size = os.stat(__file__).st_size
print(words(size))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment