Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

Toggle Format - List of Words

 Toggle Format - List of Words


The program must accept a list of words as the input. The program must print the output based on the following conditions - the given list of words present horizontally, then the program must print the list of words vertically in reverse order -It the given fist of words present vertically, then the program must print the list of words horizontally in reverse order, Finally, the program must print the total number of words as the output

Boundary Condition(s):

1<= Number of words in the last 1000

Input Format:

The first line contains a list of words separated by a space for The lines, each contains a word.

Output Format

The first line contains a list of words separated by a space (or) The lines wath contains a word.

The last line contains an integer representing the number of words in this list

Example Input/Output 1: Input

one two three four

Output four

three

4

Explanation Here the words

Skill Rack

three four.

present humntally as one two So the list of words are printed vertically in reverse order

are

Finally, the number of words in the late printed Hence the outputs

four three

two

one

4

 

SOLUTION :

PYTHON CODE: 

l=input().split()

if(len(l)==1):

    try:

        while(True):

            temp=input().strip()

            l.append(temp)

    except Exception:

        print(*l[::-1])

else:

    print(*l[::-1],sep="\n")

print(len(l))


Post a Comment

Previous Post Next Post