AJF
AJF

Reputation: 19

Simple word scrambler

counter = 0
sentence = 'Hello World'
split = str.split(sentence)

for str in split:
  c = split[counter]
  scramble = c[4] + c[0] + c[3] + c[1] + c[2]
  counter += 1
  print (scramble)

The program should rearrange each word in a string into a specific pattern but I cannot figure out how to print the scrambled text onto the same line.

Upvotes: 1

Views: 102

Answers (1)

lucians
lucians

Reputation: 2269

Here you go

counter = 0
sentence = 'Hello World'
split = str.split(sentence)

for str in split:
  c = split[counter]
  scramble = c[4] + c[0] + c[3] + c[1] + c[2]
  counter += 1
  print (scramble, end=" ")

The print function accepts an end parameter which defaults to "\n". Setting it to an empty string prevents it from issuing a new line at the end of the line.

Upvotes: 1

Related Questions