On Wed, May 18, 2011 at 11:27 AM, Cindy Lee <cindylee2...@yahoo.com> wrote: > Thanks for the advice. I seem to keep getting the same errror: > <function ReceiveAndReturn at 0x16b43b0
This "error" is fully expected. print is displaying what it's given - the function ReceiveAndReturn. In order to use the function, you need () on the end. > Any advise? Also, is the _add_ string something I should be using? >>>> help(str.__add__) > Help on wrapper_descriptor: > __add__(...) > x.__add__(y) <==> x+y No, not really. What you want to do is to parse the string given, and then edit the values in place. > ________________________________ > From: Dave Angel <da...@ieee.org> > To: Cindy Lee <cindylee2...@yahoo.com> > Cc: "tutor@python.org" <tutor@python.org> > Sent: Wednesday, 18 May 2011, 3:02 > Subject: Re: [Tutor] Sequencing > > On 01/-10/-28163 02:59 PM, Cindy Lee wrote: >> Hi Pyton Tutors thanks for adding me, >> >> I am new to Python and missed one of my classes and am not sure of my >> homework. We are currently on sequencing and are being asked to make a >> function that receives text as an argument and returns the same text, but >> with 1 added to each number. So far I have: >> >> >> def ReceiveAndReturn(): >> >> sentence=raw_input("Give me a sentence with variables in it: ") >> >> print ReceiveAndReturn >> >> >> >> could anyone give me any hints on what else needs to be added? > > As for your code so far, you've omitted the parentheses in the call to > ReceiveAndReturn. > > > > That's not a very complete assignment description. Without some example > text, I can only guess what these "sentences" might be permitted to look > like. So let me make a wild guess and see where it leads us. > > Suppose you assume that the numbers in the "sentence" will be unsigned > (positive) integers, and that they will be separated from surrounding > characters by whitespace. That's a restrictive assumption, since a sentence > might end with a number, and therefore there might be a period, not a space > after it. Similarly, a list of numbers might have commas, etc. Assume also > that extra spaces are irrelevant, so that one space between each word is > fine. > > So you're looking to parse a 'sentence' like: > > Joe had 44 baskets and 3 of them were broken. > > What you might want to do is split that string by whitespace, then loop > through the resulting list, discovering any tokens that start with a digit. > If it starts with a digit, convert it to an int, add one, and convert it > back to a string. > > Then join the tokens (strings) back together into a single string (using a > space character), and print it out. > > In my description I deliberately used several python keywords and library > function names, so that you might be able to search them out in the python > docs, to see how to apply them. > > DaveA > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor