To print sentences in reverse order while statements

Asked 2 years ago, Updated 2 years ago, 91 views

sentence='There is a sun in the mouse hole.'

i=len(sentence)-1

while i >= 0 :

    if sentence[i]=='':
        print('-')
    else:
        print('%s'% sentence[i],end='')

    i-=1    

while-loop

2022-09-20 19:05

1 Answers

A space must contain one space between single quotes.

' <= Blank

'<= Not blank

Please refer to the code below as well.

sentence='There is a sun in the mouse hole.'

i=len(sentence)-1

while i >= 0 :

    if sentence[i]==' ':
        print('-',end='')
    else:
        print('%s'% sentence[i],end='')

    i-=1


2022-09-20 19:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.