Python 3Wing 101 Integer to English word Write a Python prog

Python 3-Wing 101

Integer to English word. Write a Python program (called ql.py) that, given an integer value, outputs a string with the equivalent English text of each digit. For example, 4 is four, 12 is one two, and 8382 is eight three eight two. py has been provided for you. In particular, the user interface in the main() function has been written for you. Your goal is to complete the convert (number_str) function, where number_str holds the number (stored as a string) to convert to the equivalent English text of each digit. See comments in the ql. py code. User input is shown on lines with the > symbol. On line 1, the user enters 4 and the computer outputs \'four\' on line 2. Next, the user enters 12 (line 3) and the computer outputs \'one two\' (line 4). For a user input of 8382 (line 5), the computer outputs \'eight three eight two\' (line 6). A user input of 979 (line 7) returns \'nine seven nine\' (line 8). A user input of 123459876 outputs \'one two three four five nine eight seven six\'. Finally, the user types \'quit\' (line 9) and the program terminates. > 4 four > 12 one two > 8382 eight three eight two > 979 nine seven nine > 123459876 one two three four five nine eight seven six > quit

Solution

q1.py

l = raw_input();

## defining a dictionary data type in python

number = {\"1\":\"one\",
        \"2\":\"two\",
        \"3\":\"three\",
        \"4\":\"four\",
        \"5\":\"five\",
        \"6\":\"six\",
        \"7\":\"seven\",
        \"8\":\"eight\",
        \"9\":\"nine\"}

   while True: ## running loop until conditions break
       if l==\"quit\":
             break
        else:  
              print \' \'.join(number[i] for i in l ) ## this like getting each value from \"l\" which is a rawinput take from user via raw_input method of python.

Python 3-Wing 101 Integer to English word. Write a Python program (called ql.py) that, given an integer value, outputs a string with the equivalent English text

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site