Skip to content

Commit 829376d

Browse files
authored
Add files via upload
1 parent 090ee0f commit 829376d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

ReverseWordOrder.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Write a program (using functions!) that asks the user for
2+
# a long string containing multiple words. Print back to the
3+
# user the same string, except with the words in backwards order.
4+
5+
def string_mess(words):
6+
#split string
7+
wordlist = words.split(" ")
8+
#reverse order
9+
for i in range(int(len(wordlist)/2)):
10+
word1 = wordlist[i]
11+
wordlist[i] = wordlist[len(wordlist)-1-i]
12+
wordlist[len(wordlist)-1-i] = word1
13+
#rejoin string
14+
return " ".join(wordlist)
15+
16+
print(string_mess(input("What would you like to tell me?\n")))

0 commit comments

Comments
 (0)