def convert_num_to_word(words):
    result = []
    for w in words:
        if w.isnumeric():
            result.extend(map(lambda x: x.lower(), word(w).split()))
        else:
            result.append(w)
    return result
def numberword():
    lst = []
    count = 0
    for i in range (1, 1001):
        word = num2word.word(i)
        temp = list(word)
        lst.append(temp)
    full = np.concatenate(lst, axis = None)
    for i in range(len(full)):
        if (full[i] == ' ') | (full[i] == '-'):
            pass
        else:
            count += 1
    andcount = 3* 891
    total = count + andcount
    print(total)
Ejemplo n.º 3
0
def test_num2word_with_params():
    assert word(748) == 'Seven Hundred Fourty Eight'
Ejemplo n.º 4
0
from collections import defaultdict
import logging
import re
import sys

import num2word

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("Test logger")

word2num = {num2word.word(num).lower(): num for num in range(2, 11)}


def get_sys_argument(argument: int) -> str:
    try:
        return sys.argv[argument]
    except IndexError:
        logging.info("No file was provided")
        return ""


def read_file(file_name: str) -> str:
    try:
        with open(file_name, 'r') as input_file:
            return input_file.read()
    except FileNotFoundError:
        return []


def process_file(file_contents: str) -> list:
    file_contents = file_contents.replace("\n", " ")
    'three': 3,
    'four': 4,
    'five': 5,
    '0': 0,
    '1': 1,
    '2': 2,
    '3': 3,
    '4': 4,
    '5': 5
}

# I create two lists with the different inputs we can have for operators
op_plus = ['plus', '+']
op_minus = ['minus', '-']

if (a or c) not in numbers.keys(
) or b not in op_plus and b not in op_minus:  # I check if any of the 3 inputs is wrong
    print("I am not able to answer this question. Check your input.")
elif b in op_plus:  # if b is a plus, I add a + c
    print(word(numbers[a]), 'plus', word(numbers[c]), 'equals',
          word(numbers[a] + numbers[c]))
else:  # else, I substract a - c
    if numbers[a] >= numbers[c]:
        print(word(numbers[a]), 'minus', word(numbers[c]), 'equals',
              word(numbers[a] - numbers[c]))
    else:
        print(word(numbers[a]), 'minus', word(numbers[c]), 'equals negative',
              word(-(numbers[a] - numbers[c])))

print("Thanks for using this calculator, goodbye :)")
Ejemplo n.º 6
0
#pip install pynum2word
import num2word
fl = open('C:/Users/kshaik/Documents/Khasim2020/pythonfile1.txt', 'r')
content = fl.read()
print(content)
fl.close()
fl = open('C:/Users/kshaik/Documents/Khasim2020/pythonfile1.txt', 'a')
out = num2word.word(content)
print(out)
fl.write(out)
fl.close()
fl = open('C:/Users/kshaik/Documents/Khasim2020/pythonfile1.txt', 'r')
print(fl.read())
fl.close()