[Tutor] How do I fix this?

Lily Tran lilytran at adobe.com
Wed Aug 15 00:30:17 CEST 2012


I am trying to read  in a string from the user input and if the string is a number then I would print out the numbers + 1.  For example if the user enters:
I have 320 dollars to buy grocery.  My program would print out: I have 321 to buy grocery.  However, the code that I have listed below would print out: I have 431 dollars to buy grocery.  How do I fix this program so that it print out 321 vs. 431?

=====================================================

#!/usr/bin/python3



def WhereAreNumbers(a_list):

    for index, element in enumerate(a_list):

        if element.isdigit():

            new_number = int(element)

            print (new_number + 1, end="")

        else:

            print(element,end="")



def Test():

    answer = input("Please enter your strings:")

    if answer:

        WhereAreNumbers(answer)

Test()

==========================================

Please enter your strings:I have 320 dollars to buy grocery

I have 431 dollars to buy grocery


Thanks;


Lily
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120814/1538631d/attachment-0001.html>


More information about the Tutor mailing list