Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that, within main(), 1. Asks for the number of words the user will enter into the program 2. Then prompts for each

Write a program that, within main(), 1. Asks for the number of words the user will enter into the program 2. Then prompts for each of the words (and stores them in a list)

Once all of the words have been entered, the program must print them out in reverse order from how they were entered, and must also show what the word would be backwards. (See the sample output for an example.)

The program must use a function called backwards(), that works as specified in the function header provided below.

Note that this function does not print out any information, but returns the reversed string to the main() function that called it. The printing out of the strings will need to occur in main().

###################################################### # backwards() reverses a string and returns the result # Input: forString; a string to reverse # Output: backString; the reversed string 

(Again, do not use any built-in function or trick that circumvents the point of this assignment, or you will earn zero points. If youre not using a loop to create the backwards string, youre doing it wrong.)

Here is some sample output for hw5_part5.py, with the user input in blue. (Yours does not have to match this word for word, but it should be similar.)

linux[0]$ python hw5_part5.py How many words would you like to turn backwards: 5Please enter string #1: dog Please enter string #2: bird Please enter string #3: horse Please enter string #4: fish Please enter string #5: llama The string 'llama' reversed is 'amall'. The string 'fish' reversed is 'hsif'. The string 'horse' reversed is 'esroh'. The string 'bird' reversed is 'drib'. The string 'dog' reversed is 'god'.

linux[0]$ python hw5_part5.py How many words would you like to turn backwards: 3Please enter string #1: Kayak Please enter string #2: Racecar Please enter string #3: Stats The string 'Stats' reversed is 'statS'. The string 'Racecar' reversed is 'racecaR'. The string 'Kayak' reversed is 'kayaK'.

linux[0]$ python hw5_part5.py How many words would you like to turn backwards: 0

linux[0]$ python hw5_part5.py How many words would you like to turn backwards: 1Please enter string #1: step on NO pets The string 'step on NO pets' reversed is 'step ON no pets'.

(Some of these examples are palindromes, which means they are the same backwards and forwards. If you pay attention to the capitalization, the reversal becomes a bit clearer.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions