159k views
2 votes
Write a section of code that asks the user for their last name and then will create A new string produced by randomly splitting their name into two parts and reversing their order.

Example: "computer" may produce the result "utter comp".

1 Answer

1 vote

import random

name = input("Enter your last name: ")

w = random.randint(0,len(name)-1)

txt = name[0:w]

txt1 = name[w:]

print(txt1+" "+txt)

I hope this helps!