Yoda style

Report a typo

Everybody wants to speak like master Yoda sometimes. Create a program that transforms a given sentence into Yoda-style speech by randomly rearranging its words. Follow these steps:

  1. Accept a sentence as input from the user.

  2. Convert the input sentence into a list of words using the string.split() method.

  3. Set the random seed to 43 using random.seed(43). This ensures reproducibility of the random shuffle.

  4. Rearrange the order of words in the list and convert the shuffled list of words back into a sentence using ' '.join().

  5. Print the resulting Yoda-style sentence.

Notes:

  • You have to use random.seed(43) before shuffling to ensure consistent results.

  • The output should be a single line of text with the words in a new, randomized order.

  • Preserve the original capitalization and punctuation of the words.

Sample Input 1:

Luke, I'm your father

Sample Output 1:

your father I'm Luke,

Sample Input 2:

I will be back

Sample Output 2:

be back will I
Write a program in Python 3
import random

# your sentence is assigned to the variable
sentence = input().split()

# write your python code below


# shows the message
print(' '.join(sentence))
___

Create a free account to access the full topic