0
spelling backwards project
''' this is my code for the spelling backwards project. can someone rewrite this code but make it a recursive function''' def spell(txt): t=list(txt) for i in range(1,(len(t))+1): print(t[-i]) txt = input() spell(txt)
5 odpowiedzi
+ 6
> Why recursion?
Because it is a code project in some Python course and learners are supposed to demonstrate that they can write a recursive function. 🙃
+ 5
It's loads of times easier to just
print( the_string[ : : -1 ] )
Why go the hard way of recursion?
But anyways, this redundant ugly code does it
def spell( line ):
if len( line ):
print( line[ -1 ], end = "" )
spell( line[ : -1 ] )
else:
print()
spell( "so dead bored" )
+ 3
why are people so obsessed with recursion? It is not a magic method and is mostly inefficient.
Learn to write Python the Python way.
+ 2
Lisa
You are right, it is mostly a lesson requirement.🙃
Sad but true.
The students gets bogged down in the assignment that they often don't learn the practical methods and ends up writing inefficient verbose codes.
Or reinventing methods that already exists because they don't have the time, or are not taught to how use the language more efficiently.
+ 1
In languages where string mirroring isn't a built-in feature, I would agree with the idea of reinvention. But in Python where all the spoils go? what's the point of all the jazz shipped with the language?
Don't tell me ... it's called syllabus 😁