This code is not valid. This if block:
if(s[i]==' ' or i==k-1):
t=a[::-1]
p=p+t
a=''
is not indented.
The interpreter does not see what the if statement should do, and outputs this:
File "main.py", line 8
t=a[::-1]
^
IndentationError: expected an indented block
This means that your code doesn't output anything.
However, if I change the code to:
s=input('enter the string ')
k=len(s)
a=''
p=''
for i in range(k):
a=a+s[i]
if(s[i]==' ' or i==k-1):
t=a[::-1]
p=p+t
a=''
print(p)
then it becomes valid.
This program outputs the input but with each word reversed in the sentence.
But, there's a twist.
For example:
if you input 'This is a sentence.',
it outputs ' siht si a.ecentnes'
Notice that there is a spacebar before the 'siht' but not before the '.ecentnes'.
This is because the program includes the spacebar when reversing, not just the word itself.
So, that's what it does.