Created
August 9, 2017 19:47
-
-
Save jgarciabu/3331667a40823105386f0e06b98b056a to your computer and use it in GitHub Desktop.
Ex 15 List Reverse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Write a program (using functions!) that asks the user for a long string | |
containing multiple words. Print back to the user the same string, except with | |
the words in backwards order. For example, say I type the string: | |
My name is Michele | |
Then I would see the string: | |
Michele is name My | |
shown back to me. | |
@author: Jeff Garcia | |
""" | |
def reverse_input(phrase): | |
result = phrase.split(" ") | |
newlist = reversed(result) | |
finallist = " ".join(newlist) | |
return finallist | |
print(reverse_input(input("Enter a phrase and I'll recite it backwards:"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment