I figure out how to do this.

Here is the code that would allow me to print 320 to 321:


def WhereAreNumbers(a_list):

    numberString=''

    for index, element in enumerate(a_list):

       if element.isdigit():

           numberString += element

       else:

            if numberString != "":

                print(int(numberString)+1,end="")

                numberString = ""

            print(element,end="")

    if numberString != "":

        print(int(numberString)+1,end="")




def Test():

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

    if answer:

        WhereAreNumbers(answer)


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


Thanks;


Lily

From: Lily Tran <[email protected]<mailto:[email protected]>>
Date: Tue, 14 Aug 2012 15:30:17 -0700
To: "[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Subject: How do I fix this?

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
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to