0

I want to print out two 'print' sentences in one line, what should I do? (I want to print that sentence only once.)

sentence = input("Enter a text.:")
for i in range(len(sentence)-1,-1,-1):
    print("Received string :",sentence,"Inverse order of inputted string")
    print(sentence[i],end='')
001
  • 13,291
  • 5
  • 35
  • 66
  • Related: [Reverse a string in Python](https://stackoverflow.com/questions/931092/reverse-a-string-in-python). – wwii Apr 12 '21 at 15:26

2 Answers2

0

Maybe you wish for:

sentence = input("Enter a text:")
print(f"Received string: {sentence}\nInverse order of inputted string: {sentence[::-1]}")

with a for loop:

sentence = input("Enter a text:")
print(f"Received string:\n{sentence}","\nInverse order of inputted string:")
for i in range(len(sentence)-1,-1,-1):
  print(sentence[i],end='')
David Meu
  • 1,527
  • 9
  • 14
0

Your syntax is correct. The problem is that you're printing a "received string" message at each step of your reversal. Simply move that line out of your for loop and you're good!

print("Received string :",sentence,"Inverse order of inputted string")
for i in range(len(sentence)-1,-1,-1):
  print(sentence[i],end='')
ZackWolf
  • 104
  • 1
  • 4