[Python] Given a sentence, return a sentence with the words reversed

Discussão em 'Python' iniciado por Stack, Maio 25, 2025.

  1. Stack

    Stack Membro Participativo

    def master_yoda(text):
    txt_elements=text.split()
    index=-1
    reverse=[]
    i=0
    while i <= len(txt_elements):
    reverse.append(txt_elements[index])
    index=index-1
    i+=1
    final=' '.join(reverse)
    return final
    print(master_yoda('i adore that'))


    I cannot understand why I keep on getting errors about unindentation.

    Here is an example:

    • Input: "I am beautiful"
    • Output: "beautiful am I"

    Continue reading...

Compartilhe esta Página