Search code examples
python-3.xpseudocode

Assignment 5-3 Pseudocode check


I have done this assignment but I just want someone to check it to make sure that it is correct. Instructions below:

Create pseudocode or a flowchart that logically outlines the steps that will allow the player to move between rooms using commands to go North, South, East, and West. Be sure to address the following:

  • What input do you need from the player? How will you prompt the player for that input? How will you validate the input?
  • What should the program do if the player enters a valid direction? What output should result?
  • What should the program do if the player enters an invalid direction? What output should result?
  • How will you control the program flow with decision branching and loops?

Storyboard map

This is my code:

START 
currentRm=’Foyer’
PRINT ‘You are in the Foyer
BEGIN LOOP
    INPUT ‘Which direction do you want to go?’
    IF currentRm IS ‘Foyer’
        IF direction IS ‘East’
                currentRm = ‘Kitchen’ 
                OUTPUT ‘You are in the Kitchen’
        ELSE
                OUTPUT ‘Invalid Direction.  Try again’

    ELIF currentRm IS ‘Kitchen’
    INPUT ‘Where do you want to go?’
        IF direction IS ‘North’
                            currentRm = ‘Living Room’
                OUTPUT’You are in the Living Room’
        ELIF direction IS ‘South’
                currentRm = ‘Dining Room’
                OUTPUT’You are in the Dining Room’
        ELIF direction IS ‘East’
                        currentRm = ‘Bedroom’
                OUTPUT ‘You are in the Bedroom’
        ELIF direction IS ‘West’
                            currentRm = ‘Foyer’
                OUTPUT ‘You are in the Foyer’
        ELSE
                OUTPUT  ‘Invalid Direction.  Try again’
    ELIF currentRM IS ‘Living Room’
    INPUT ‘Where do you want to go?’
        IF direction IS ‘East’
                currentRm = ‘Gaming Room’
                PRINT ‘You are in the Gaming Room’
        ELIF direction IS ‘South’   
                currentRm = ‘Kitchen’
                OUTPUT ‘You are in the Kitchen’
        ELSE
                OUTPUT ‘Invalid Direction.  Try again’

    ELIF currentRm IS ‘Gaming Room’
    INPUT ‘Where do you want to go?’
        IF direction IS ‘West’
                currentRm = ‘Living Room’
                OUTPUT ‘You are in the Living Room’
        ELSE
                OUTPUT ‘Invalid Direction.  Try again’

        ELIF currentRm IS ‘Dining Room’
        INPUT ‘Where do you want to go?’
        IF direction IS ‘North’
                currentRm = ‘Kitchen’
                OUTPUT ’You are in the Kitchen’
        ELIF direction IS ‘East’
                currentRm = ‘Garage’
                OUTPUT ‘You are in the Garage’
        ELSE
                OUTPUT ‘Invalid Direction.  Try again’

    ELIF currentRm IS ‘Garage’
    INPUT ‘Where do you want to go?’
        IF direction IS ‘West’
                 currentRm = ‘Dining Room’
                OUTPUT ‘You are in the Dining Room’
        ELSE
                OUTPUT ‘Invalid Direction.  Try again’

    ELIF currentRm IS ‘Bedroom’
    INPUT ‘Where do you want to go?’
                IF direction IS ‘West’
                 currentRm = ‘Kitchen’
                OUTPUT ‘You are in the Kitchen’
        ELIF direction IS ‘North’
                currentRm = ‘Bathroom’
                OUTPUT ‘You are in the Bathroom’
                ELSE
                   OUTPUT ‘Invalid Direction.  Try again’
    ELIF currentRm IS ‘Bathroom’
    INPUT ‘Where do you want to go?’
        IF direction is ‘South’
                currentRm = ‘Bedroom’
                OUTPUT ‘You are in the Bedroom’
        ELSE
                OUTPUT ‘Invalid Direction.  Try again’
    
END LOOP
        IF currentRm = ‘Gaming Room’
        OUTPUT ‘Game Over’

Solution

  • Some remarks:

    • When the current room is not "Foyer", the code will ask two questions:

      ‘Which direction do you want to go?’
      ‘Where do you want to go?’
      

      This is not right. The first question is asked irrespective of which room you're in, and it shouldn't ask that second question for specific rooms. So remove that INPUT statement from all those ELIF blocks.

    • The loop never ends, and as there are no indications in the instructions that the loop should end, this is fine. But this also means that the last two statements in your program will never execute:

          IF currentRm = ‘Gaming Room’
          OUTPUT ‘Game Over’
      

      If it was intended that when the user enters the Gaming Room that this output should appear, and possibly the program should end, then you need to move this code inside the loop, where you already detect that the user enters that room:

         IF direction IS ‘East’
                  currentRm = ‘Gaming Room’
                  PRINT ‘You are in the Gaming Room’
                  OUTPUT ‘Game Over’
                  EXIT LOOP
      
    • You can avoid some code repetition and combine all variants of PRINT ‘You are in the Kitchen’ by PRINT ‘You are in the ’, currentRm and move that statement at a place where it is executed for all cases.

    • In a real programming language, you would create a graph data structure and avoid these many IF..ELIF blocks. The looks of that data structure would depend on that programming language.

    • You should improve the indentation of your code a bit. Make sure that after an IF or ELIF statement the code is more indented (4 spaces is a good standard), and that all statements that are part of that block are all at the same indentation level.