Jump to content

en English cardinal, python Z13588
en Implementation

ⵙⴳ Wikifunctions
No edit summary
ERROR: number is too large for this algorithm
ⴰⵣⵔⵉⴳ 11: ⴰⵣⵔⵉⴳ 11:
"Z1K1": "Z16",
"Z1K1": "Z16",
"Z16K1": "Z610",
"Z16K1": "Z610",
"Z16K2": "def Z13587(Z13587K1):\n # define the units and tens place\n ones = [\"\", \"one \", \"two \", \"three \", \"four \", \"five \", \"six \", \"seven \", \"eight \", \"nine \", \"ten \", \"eleven \", \"twelve \", \"thirteen \", \"fourteen \", \"fifteen \", \"sixteen \", \"seventeen \", \"eighteen \", \"nineteen \"]\n tens = [\"\", \"\", \"twenty\", \"thirty\", \"forty\", \"fifty\", \"sixty\", \"seventy\", \"eighty\", \"ninety\"]\n units = [(\"quattuordecillion\", 1_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000),(\"tredecillion\", 1_000_000_000_000_000_000_000_000_000_000_000_000_000_000),(\"duodecillion\", 1_000_000_000_000_000_000_000_000_000_000_000_000_000),(\"undecillion\", 1_000_000_000_000_000_000_000_000_000_000_000_000),(\"decillion\", 1_000_000_000_000_000_000_000_000_000_000_000),(\"nonillion\", 1_000_000_000_000_000_000_000_000_000_000),(\"octillion\", 1_000_000_000_000_000_000_000_000_000),(\"septillion\", 1_000_000_000_000_000_000_000_000),(\"sextillion\", 1_000_000_000_000_000_000_000),(\"quintillion\", 1_000_000_000_000_000_000), (\"quadrillion\", 1_000_000_000_000_000), (\"trillion\", 1_000_000_000_000), (\"billion\", 1_000_000_000), (\"million\", 1_000_000), (\"thousand\", 1_000), (\"hundred\", 100), (\"\", 1)]\n\n # function to convert numbers less than 1000 to words\n def words(Z13587K1):\n if Z13587K1 == 0:\n return \"\"\n elif Z13587K1 \u003C= 19:\n return ones[Z13587K1]\n elif Z13587K1 \u003C= 99:\n tens_unit = tens[Z13587K1 // 10]\n ones_unit = ones[Z13587K1 % 10]\n return tens_unit + \"-\" + ones_unit if ones_unit else tens_unit\n else:\n return ones[Z13587K1 // 100] + \"hundred and \" + words(Z13587K1 % 100)\n\n # convert numbers to words\n if Z13587K1 == 0:\n return \"zero\"\n elif Z13587K1 \u003C 0:\n return \"negative \" + Z13587(-Z13587K1)\n else:\n result = \"\"\n for unit_name, factor in units:\n count, Z13587K1 = divmod(Z13587K1, factor)\n if count \u003E 0:\n if factor == 100:\n result = result + \" \" + ones[count] + unit_name\n elif factor == 1:\n result = result + \" and \" + words(count) + unit_name\n else:\n result = result + \" \" + words(count) + unit_name\n if (result.startswith(\" and \")): result = result[5:]\n return result.strip()"
"Z16K2": "def Z13587(Z13587K1):\n # define the units and tens place\n ones = [\"\", \"one \", \"two \", \"three \", \"four \", \"five \", \"six \", \"seven \", \"eight \", \"nine \", \"ten \", \"eleven \", \"twelve \", \"thirteen \", \"fourteen \", \"fifteen \", \"sixteen \", \"seventeen \", \"eighteen \", \"nineteen \"]\n tens = [\"\", \"\", \"twenty\", \"thirty\", \"forty\", \"fifty\", \"sixty\", \"seventy\", \"eighty\", \"ninety\"]\n units = [(\"quattuordecillion\", 1_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000),(\"tredecillion\", 1_000_000_000_000_000_000_000_000_000_000_000_000_000_000),(\"duodecillion\", 1_000_000_000_000_000_000_000_000_000_000_000_000_000),(\"undecillion\", 1_000_000_000_000_000_000_000_000_000_000_000_000),(\"decillion\", 1_000_000_000_000_000_000_000_000_000_000_000),(\"nonillion\", 1_000_000_000_000_000_000_000_000_000_000),(\"octillion\", 1_000_000_000_000_000_000_000_000_000),(\"septillion\", 1_000_000_000_000_000_000_000_000),(\"sextillion\", 1_000_000_000_000_000_000_000),(\"quintillion\", 1_000_000_000_000_000_000), (\"quadrillion\", 1_000_000_000_000_000), (\"trillion\", 1_000_000_000_000), (\"billion\", 1_000_000_000), (\"million\", 1_000_000), (\"thousand\", 1_000), (\"hundred\", 100), (\"\", 1)]\n\n # function to convert numbers less than 1000 to words\n def words(Z13587K1):\n if Z13587K1 == 0:\n return \"\"\n elif Z13587K1 \u003C= 19:\n return ones[Z13587K1]\n elif Z13587K1 \u003C= 99:\n tens_unit = tens[Z13587K1 // 10]\n ones_unit = ones[Z13587K1 % 10]\n return tens_unit + \"-\" + ones_unit if ones_unit else tens_unit\n else:\n return ones[Z13587K1 // 100] + \"hundred and \" + words(Z13587K1 % 100)\n\n # convert numbers to words\n if Z13587K1 == 0:\n return \"zero\"\n elif Z13587K1 \u003C 0:\n return \"negative \" + Z13587(-Z13587K1)\n else:\n result = \"\"\n for unit_name, factor in units:\n count, Z13587K1 = divmod(Z13587K1, factor)\n if count \u003E 999:\n #ERROR: number is too large for this algorithm\n return \"ERROR: number is too large for this algorithm\"\n if count \u003E 0:\n if factor == 100:\n result = result + \" \" + ones[count] + unit_name\n elif factor == 1:\n result = result + \" and \" + words(count) + unit_name\n else:\n result = result + \" \" + words(count) + unit_name\n if (result.startswith(\" and \")): result = result[5:]\n return result.strip()"
}
}
},
},

ⵜⵓⵏⵖⵉⵍⵜ ⵏ 04:44, 6 ⵎⴰⵕⵚ 2024

This page displays in a limited way without JavaScript.