Aller au contenu

en English cardinal, python Z13588
fr Implémentation

Pɩlɩɩna Wikifunctions
strip leading "and
Aucun résumé des modifications
Caŋa 11: Caŋa 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 = [(\"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 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()"
}
}
},
},

6 Lakɩŋ fenaɣ 2024 à 03:35 wiye ñɔɔzɩtʋ kɩlɛɣzɩtʋ

Affichage réduit de cette page sans Javascript.