PTA 1009 ironic Python implementation

topic:

Given a word of English, asking you to write a program, all the words of the sentence order reversed output.

Input formats:

Test input comprises a test case, given the string length does not exceed a total of 80 in a row. String composed of several words and a number of spaces, where the word is English letters (case is case) consisting of string, separated by a space between words, the input end of the sentence to ensure that no extra space.

Output formats:

Each test case output per line, output sentence after the reverse.

Sample input:

Hello World Here I Come

Sample output:

Come I Here World Hello

Python code:

str = list(input().split())
str.reverse()
for i in range(len(str)):
    if i == len(str)-1:
        print(str[i])
    else:
        print(str[i],end=' ')

Guess you like

Origin blog.csdn.net/qq_32188669/article/details/94578491