[Tutor] Tutor Digest, Vol 26, Issue 56

Alan Gauld alan.gauld at freenet.co.uk
Tue Apr 18 12:52:25 CEST 2006


----- Original Message ----- 
From: <nywbon001 at mail.uct.ac.za>
Subject: Re: [Tutor] Tutor Digest, Vol 26, Issue 56


Please don't reply to the digest message, we get all of the digest plus
your question tagged on at the end!

>>
>> End of Tutor Digest, Vol 26, Issue 56
>> *************************************
>>
> I  want to build a function which will reverse my input sentance.if i try 
> to
> use the rervese it does not work here is my function:
>
> def reversor():
>  for i in string(a):

What is string(a)? Indeed, what is a?
string is not a built in function in Python.
Do you mean str(a)? str(a) will attempt to convert a to a string.
It would be better to pass a string into the function as a parameter.

>      l=[]

This creates an empty list, l

>      if a==string:
>         l.reversed(a)

This says that if 'a' equals string (which you show to be some kind
of function object) then call l.reversed(a)

There is no method of a list called reversed(), there is one
called reverse() but it doesn't have a parameter. And it
reverses the list which in this case is empty.

>      print l

So you print an empty list.

Did you try to run the code? What error did you get?
What did you think the code was doing? What did you
expect to happen?

Armed with this information we might be able to help you
solve your problem.

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list