Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index error for particular inputs Eg. "thousand" #13

Closed
Apaar opened this issue May 24, 2017 · 2 comments
Closed

Index error for particular inputs Eg. "thousand" #13

Apaar opened this issue May 24, 2017 · 2 comments
Assignees
Labels

Comments

@Apaar
Copy link

Apaar commented May 24, 2017

When we input stuff like only 'thousand', 'million', 'billion' it gives a list index error.Strangely does not happen for just 'hundred'.

One sample error -

i=w2n.word_to_num('billion')
Traceback (most recent call last):
File "", line 1, in
File "/home/anaconda3/lib/python3.6/site-packages/word2number/w2n.py", line 178, in word_to_num
billion_multiplier = number_formation(clean_numbers[0:billion_index])
File "/home/anaconda3/lib/python3.6/site-packages/word2number/w2n.py", line 104, in number_formation
return numbers[0]
IndexError: list index out of range

@akshaynagpal
Copy link
Owner

@Apaar
Thanks for pointing this out. I will look into this ASAP.
Meanwhile, you're also welcome to fix the error and submit a Pull Request. If it passes all the tests, it will be merged most probably.

@lhami
Copy link

lhami commented Nov 25, 2018

The issue as stated is solved, but there are some related issues still existing. Writing something like "million and one" will throw an index error:

w2n.word_to_num("thousand and one")
Traceback (most recent call last):
File "", line 1, in
w2n.word_to_num("thousand and one")
File "c:\users\leah\appdata\local\programs\python\python37\lib\site-packages\word2number\w2n.py", line 197, in word_to_num
thousand_multiplier = number_formation(clean_numbers[0:thousand_index])
File "c:\users\leah\appdata\local\programs\python\python37\lib\site-packages\word2number\w2n.py", line 104, in number_formation
return numbers[0]
IndexError: list index out of range

And for some reason "hundred and three" gets read as 300.

For the moment, I've fixed this in my personal code by checking for hundred/thousand/million/billion at the start of a string and putting "one " in front before the conversion. If that's an acceptable solution, I could incorporate this fix in the package itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants