Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Question : a. Write a function that is given a phrase and returns the first word in that phrase. For example, given the quick

Python Question :

a. Write a function that is given a phrase and returns the first word in that phrase. For example, given the quick brown fox, your function should return the.

b. Write a function that is given a phrase and returns the phrase we get if we take out the first word from the input phrase. For example, given the quick brown fox, your function should return quick brown fox

c. Use the functions from a and b to implement a function that given a phrase, it reverses the words in that phrase (and returns it) For example, given the quick brown fox jumps over a lazy dog, your function should return dog lazy a over jumps fox brown quick the.

d. Write a driver program, ie. main()function, that interacts with the user and uses function you wrote for c.

This is my code. But i cant figure out part C.

def first_word (s): blank = s.find(" ") first_word = s [0:blank] return first_word

def remain_word (s): blank = s.find(" ") rest_words = s [blank+1 : ] return rest_words

def reversed_word (s): s = remain_word (s) + " " + first_word (s) return s

def main (): s = input("Please enter a sentence: ") print (reversed_word(s))

main()

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

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions