Number to english words in python assignment expert

Number to English Words

Write a program to convert a non-negative integer

The input will be a single line containing an integer

The output should be a single line containing the representation of the English words of number

For example, if the given number is 123, your code should print the English words representation, which is

One Hundred Twenty Three

Sample Input 1

123

Sample Output 1

One Hundred Twenty Three

Sample Input 2

10005

Sample Output 2

Ten Thousand Five

ones = {0: '', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six',
        7: 'Seven', 8: 'Eight', 9: 'Nine', 10: 'Ten', 11: 'Eleven', 12: 'Twelve',
        13: 'Thirteen', 14: 'Fourteen', 15: 'Fifteen', 16: 'Sixteen',
        17: 'Seventeen', 18: 'Eighteen', 19: 'Nineteen'}
tens = {2: 'Twenty', 3: 'Thirty', 4: 'Forty', 5: 'Fifty', 6: 'Sixty',
        7: 'Seventy', 8: 'Eighty', 9: 'Ninety'}
illions = {1: 'Thousand', 2: 'Million', 3: 'Billion'}




def convertIntegerIntoWord[i]:
    if i == 0:
        return 'zero'
    return getNumberPosition[i]




def getNumberPosition[i]:
    if i < 20:
        return ones[i]
    if i < 100:
        return joinWords[tens[i // 10], ones[i % 10]]
    if i < 1000:
        return divItems[i, 100, 'Hundred']
    for inumber, iname in illions.items[]:
        if i < 1000**[inumber + 1]:
            break
    return divItems[i, 1000**inumber, iname]




def divItems[position, inumber, iname]:
    return joinWords[
        getNumberPosition[position // inumber],iname,getNumberPosition[position % inumber],
    ]




def joinWords[*words]:
    return ' '.join[filter[bool, words]]




number = int[input[]]
print[convertIntegerIntoWord[number]]

Number to English Words

Write a program to convert a non-negative integer

The input will be a single line containing an integer

The output should be a single line containing the representation of the English words of number

For example, if the given number is 123, your code should print the English words representation, which is

One Hundred Twenty Three

Sample Input 1

123

Sample Output 1

One Hundred Twenty Three

Sample Input 2

10005

Sample Output 2

Ten Thousand Five

Sample Input 3

1234567891

Sample Output 3

One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One

for this question you have answered like:

but we are getting "ModuleNotFoundError: No module named 'num2words'"

import num2words
print[num2words.num2words[input[]]]

low = ["Zero",
       "One",
       "Two",
       "Three",
       "Four",
       "Five",
       "Six",
       "Seven",
       "Eight",
       "Nine"]


then = ["Ten",
        "Eleven",
        "Twelve",
        "Thirteen",
        "Fourteen",
        "Fifteen",
        "Sixteen",
        "Seventeen",
        "Eighteen",
        "Nineteen"]


mid = ["Ten",
       "Twenty",
       "Thirty",
       "Forty",
       "Fifty",
       "Sixty",
       "Seventy",
       "Eighty",
       "Ninety"]


high = ["Hundred",
        "Thousand",
        "Million",
        "Billion"]


def hund2word[hund: int]:
    word = ""
    a = hund % 100
    if 0 != a and a < 10:
        word += low[a]
    elif 10 

Chủ Đề