# Python problem- In written text small numbers are often written out- e.docx

Jan. 31, 2023
1 of 2

### Python problem- In written text small numbers are often written out- e.docx

• 1. Python problem: In written text small numbers are often written out, e.g. you'd write 'I have two brothers and one sister', rather than 'I have 2 brothers and 1 sister'. In this problem you will implement a function convertSmall() that takes as input a text (i.e., string) s and returns the text s with small numbers (integers between 0 and 6) converted to their names. >>> convertSmall('I have 2 brothers and 1 sister') 'I have two brothers and one sister' >>> convertSmall('I have 8 brothers and 5 sisters') 'I have 8 brothers and five sisters' Solution def convertSmall(str): "This function converts text with small numbers to their names" sArr = str.split() for i, word in enumerate(sArr): if (word == '0') : sArr[i] = 'zero' if (word == '1') : sArr[i] = 'one' if (word == '2') : sArr[i] = 'two' if (word == '3') : sArr[i] = 'three' if (word == '4') : sArr[i] = 'four' if (word == '5') : sArr[i] = 'five' if (word == '6') :
• 2. sArr[i] = 'six' return ' '.join(sArr); Output: >>>convertSmall('I have 2 brothers and 1 sister') I have two brothers and one sister >>>convertSmall('I have 8 brothers and 5 sisters') I have 8 brothers and five sisters