Python sentence reverser -
i trying create program in python in user enters sentence , reversed sentenced printed. code have far is:
sentence = raw_input('enter sentence') length = len(sentence) in sentence[length:0:-1]: = print a,
when program run misses out last letter if word 'hello' print 'olle'. can see mistake?
you need remove 0
indices range, instead can use :
sentence[length::-1]
also not don't need loop on string , use assignments , length
can print reversed string.
so following code job :
print sentence[::-1]
demo :
>>> s="hello" >>> print s[::-1] 'olleh'
Comments
Post a Comment