[Tutor] Sequencing

Cindy Lee cindylee2321 at yahoo.com
Thu May 19 12:10:47 CEST 2011


Sorry I am still lost. So I am suppose to use a string? Something like: (just not sure is the right string...)



def ReceiveAndReturn():
    str="I have 5 Apples and 6 oranges";
    print "str._add1"
ReceiveAndReturn()

Want output to be:
I have 6 Apples and 7 oranges


________________________________
From: Alan Gauld <alan.gauld at btinternet.com>
To: tutor at python.org
Sent: Wednesday, 18 May 2011, 8:07
Subject: Re: [Tutor] Sequencing


"Cindy Lee" <cindylee2321 at yahoo.com> wrote
> ...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: ")

The assignment says it should receive the text *as an argument*
That means you don't read it using raw_input.

Its not clear what the adding one to each number bit means.
If we make some assumptions:

"2 cats sat on a mat" -> "3 cats sat on a mat"

but not

"Two cats sat on a mat" -> "Three cats sat on a mat"

In other words we are only detecting strings of decimal digits
not numeric words.

Then we can search the string(a sequence) for consecutive
numbers. Convert them from strings to numbers and add one
Then insert into the output string. Thats the tricky bit! :-)

Have a go, post your code and we will try to help when
you get stuck.

HTH,


-- Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110519/6fb4cf10/attachment.html>


More information about the Tutor mailing list