Advertisement
Niyaz1712

kk,

Apr 30th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. function sentence_filter(sentence){
  2.   GET sentence;
  3.   GLOBAL sentenceLoop;
  4.   UPPERCASE sentence;
  5.   for (SET punctuation;punctuation in sentence?;REMOVE punctuation in sentence) // FOR
  6.   SET checkSentence = (REMOVE spaces in sentence);
  7.   if(checkSentence is empty?) // IF
  8.     /OUTPUT "ERROR! You did not enter in a sentence."/;
  9.   else // ELSE
  10.     SET sentenceLoop to False;
  11.   return sentence; // RETURN
  12. }
  13.  
  14. function word_filter(word, sentence){
  15.   GET sentence;
  16.   GLOBAL wordLoop;
  17.   UPPERCASE sentence;
  18.   for (SET punctuation;punctuation in word?;REMOVE punctuation in word) // FOR
  19.   SET wordLength to (COUNT how many words are in word);
  20.   REMOVE spaces in word;
  21.   if (word equal to ""?) // IF
  22.     /OUTPUT "ERROR! You did not enter in a word."/;
  23.   else if (wordLength more than 1?) // ELSE IF
  24.     /OUTPUT ("ERROR! You entered in more than one word.")/;
  25.   else if (word not in sentence?) // ELSE IF
  26.     /OUTPUT "ERROR! The word is not in the sentence."/;
  27.   else // ELSE
  28.     SET wordLoop to False;
  29.   return word; // RETURN
  30. }
  31.  
  32. function word_locate(sentence, word){
  33.     GET sentence and word;
  34.     SPLIT sentence;
  35.     SET wordPositions to “”;
  36.     SET loopCounter to 0;
  37.     SET wordCount to (COUNT the times the word is in the sentence);
  38.     while (loopCounter < wordCount){ // WHILE
  39.         SET position to (INDEX the first occurrence of the word in the sentence);
  40.         REPLACE first occurrence of the word in sentence with any punctuation ;
  41.         ADD 1 to position;
  42.         CAST string to position;
  43.         APPEND (position with a space after it) to wordPositions;
  44.         ADD 1 to loopCounter;
  45.    }
  46.     return wordPositions; // RETURN
  47. }
  48.  
  49. function restart(decision){
  50.     GET decision;
  51.     GLOBAL mainLoop;
  52.     GLOBAL decisionLoop;
  53.     UPPERCASE decision;
  54.     if (decision equal "Y"?) // IF
  55.         decision = "The program has restarted.";
  56.     else if (decision equal "N"?) // ELSE IF
  57.         SET decision = "The program has ended.";
  58.         SET decisionLoop to False;
  59.         SET mainLoop to False;
  60.     else // ELSE
  61.         SET decision = "ERROR! You did not enter in a decision.";
  62.     return decision; // RETURN
  63. }
  64.  
  65. START;
  66. SET mainLoop to True;
  67. while (mainLoop equals to True){ // WHILE
  68.   /OUTPUT "A453 - Programming Project - Task 1"/;
  69.   SET sentenceLoop to True;
  70.   while (sentenceLoop equals to True){ // WHILE
  71.     /OUTPUT "Enter in a sentence."/;
  72.     /INPUT sentence/;
  73.     call sentence_filter(sentence); // FUNCTION
  74.   }
  75.   /OUTPUT sentence/;
  76.   SET wordLoop to True;
  77.   while (wordLoop equals to True){ // WHILE
  78.     /OUTPUT "Enter in a word."/;
  79.     /INPUT word/;
  80.     call word_filter(word, sentence); FUNCTION
  81.   }
  82.   /OUTPUT word/;
  83.   call word_locate(sentence, word); // FUNCTION
  84.   /OUTPUT wordPositions/;
  85.   SET decisionLoop to True;
  86.   while (decisionLoop equals True){ // WHILE
  87.     /OUTPUT "Would you like to restart the program? (Y/N)"/;
  88.     /INPUT decision/;
  89.     call restart(decision); // FUNCTION
  90.   }
  91.   /OUTPUT decision/;
  92. }
  93. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement