Exercise 4. (Reverse) Write a program called reverse.py that accepts strings from standard input, and writes them in reverse order to standard output.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section8.1: I/o File Stream Objects And Functions
Problem 6E
icon
Related questions
Question
Exercise 4. (Reverse) Write a program called reverse.py that accepts strings from standard input, and writes them in reverse
order to standard output.
>- "/workspace/project3
$ python3 reverse.py
bo lt on
<ctrl-d>
no t l o b
E reverse.py
import stdio
# Accept all the strings from standard input and store them in a
list a.
# Reverse a.
for i in range (...):
# Iterate over half of the list a...
# Exchange element at i in a with the element at len(a) - i - 1.
# Write a to standard output.
for i in range (...):
if
... :
# If i is not the last column, write a[i] with
a
space after.
else:
# Otherwise, write the element with
a newline after.
Transcribed Image Text:Exercise 4. (Reverse) Write a program called reverse.py that accepts strings from standard input, and writes them in reverse order to standard output. >- "/workspace/project3 $ python3 reverse.py bo lt on <ctrl-d> no t l o b E reverse.py import stdio # Accept all the strings from standard input and store them in a list a. # Reverse a. for i in range (...): # Iterate over half of the list a... # Exchange element at i in a with the element at len(a) - i - 1. # Write a to standard output. for i in range (...): if ... : # If i is not the last column, write a[i] with a space after. else: # Otherwise, write the element with a newline after.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning