0

I am finding it hard to find what this pseudocode outputs. Does it mean for example if you entered the name Peter. Would the output be pet? Or the letter t?

Display enter a name
Get name
Length = length of name 
Index = length -1 
While index >= 0 Do
      DISPLAY name(index)
      Index = index -2 
ENDWHILE
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • Pseudocodes have nothing to do with python. – Zoli Jun 09 '16 at 19:04
  • Can't you execute it step by step on paper? This is _pseudocode_, not Python. – ForceBru Jun 09 '16 at 19:04
  • I don't understand the psedocode. As in for example what it's doing exactly. I just want to understand what it's saying. Because I don't know if it's taking numbers away from a name a user enters. Or if it's removing all letters and keeping the 3 letter of say Peter. Because it's -2. Thanks for the quick reply. – Simplybestwinner Jun 09 '16 at 19:09
  • It displays the letters in reverse order, skipping one every time. So `Timothy` gets displayed as `ytmT`. – trincot Jun 09 '16 at 19:14
  • Thanks I understood now. Had the wrong idea I was thinking just -2 letters is too simple. It's the index= part. Thanks again – Simplybestwinner Jun 09 '16 at 19:19

1 Answers1

0

It displays the letters in reverse order, skipping one every time. So Timothy gets displayed as ytmT.

Here is an implementation in JavaScript, which you can test:

var display = '';
var name = prompt("Enter a name:");
length = name.length; 
index = length - 1;
while (index >= 0) {
      display += name[index];
      index = index -2 
}
alert(display);
trincot
  • 317,000
  • 35
  • 244
  • 286