[在此处输入图像说明] [1]
from word2number import w2n
w2n.word_to_num('one')
1
q = input('write your number letters : ')
>>>two
w2n.word_to_num('q')
>>>NameError: name 'two' is not defined
我使用word2number包将单词转换为数字,如; 2 = 2.当我从用户那里获取输入并想转换该输入时,系统错误。
答案 0 :(得分:0)
请将完整代码发布为您尝试的文本,但却会出现错误。
但Word2number文档中的代码对我来说很好。
https://pypi.org/project/word2number/
Python 3
from word2number import w2n
print(w2n.word_to_num('point one'))
输出: 0.1
Python 2
from word2number import w2n
print w2n.word_to_num('point one')
输出: 0.1