What would be the Python code for this pseudo code? Pseudocode: INITIALIZE players_room = “Start” Print “Collect 6 c
Posted: Mon Jun 06, 2022 1:55 pm
What would be the Python code for this pseudo code?
Pseudocode:
INITIALIZE players_room = “Start”
Print “Collect 6 camping items for survival and
avoid getting eaten by a bear. Move
commands: South, North, East, West Add to
Inventory: get ‘item name’”
Loop begin
INPUT the direction
IF players_room is “Start”
IF direction is “South”
Players_room = “Meadow of
flowers”
Else if direction is “East”
Players_room = “Tent”
Else if direction is “West”
Players_room = “Snakes”
Else
OUTPUT “You cannot go that
direction”
Else IF players_room is “Tent”
IF direction is “West”
Players_room = “Start”
Else
OUTPUT “WRONG WAY”
Else IF players_room is “Snakes”
IF direction is “East”
Players_room = “Start”
Else if direction is “South”
Players_room = “Water filter”
Else
OUTPUT “Go another way”
Else IF players_room is “Water filter”
IF direction is “East”
Players_room = “Lighter”
Else if direction is “South”
Players_room = “Food”
Else if direction is “North”
Players_room = “Snakes”
Else
OUTPUT “You must go another direction”
Else IF players_room is “Food”
IF direction is “East”
Players_room = “Spider web”
Else if direction is “North”
Players_room = “Water filter”
Else
OUTPUT “Go another direction”
Else IF players_room is “Spider web”
IF direction is “East”
Players_room = “Swiss army
knife”
Else if direction is “West”
Players_room = “Food”
Else if direction is “North”
Players_room = “Meadow of flowers”
Else
OUTPUT “You must go a different direction”
Else IF players_room is “Swiss army knife”
IF direction is “West”
Players_room = “Spider web”
Else
OUTPUT “Wrong direction”
Else IF players_room is “Meadow of flowers”
IF direction is “East”
Players_room = “Sleeping bag”
Else if direction is “South”
Players_room = “Spider web”
Else if direction is “North”
Players_room = “Start”
Else if direction is “West”
Players_room = “Lighter”
Else
OUTPUT “Frustrating, isn’t it?”
Else IF players_room is “Sleeping bag”
IF direction is “West”
Players_room = “Meadow of
flowers”
Else
OUTPUT “You need to collect all of the items, go another
way”
Else IF players_room is “Bear den”
IF direction is “South”
Players_room = “Sleeping bag”
Else
OUTPUT “Uh oh”
Else IF players_room is “Lighter”
IF direction is “East”
Players_room = “Meadow of
flowers”
Else if direction is “West”
Players_room = “Water filter”
Else
OUTPUT “You may not want to go North or South”
Pseudocode to get an item:
Get an Item
Inventory = “Nothing”
If players_room is “Lighter”
Print “Now I will have fire!”
Input get_item
Add lighter to inventory
If players_room is “Tent”
Print “I have shelter!”
Input get_item
Add Tent to inventory
If players_room is “Food”
Print “I was so hungry and now I can eat!”
Input get_item
Add Food to inventory
If players_room is “Water filter”
Print “Dehydration no more! I have water!”
Input get_item
Add Water filter to inventory
If players_room is “Swiss army knife”
Print “Yes! Tools!”
Input get_item
Add Swiss army knife to inventory
If players_room is “Sleeping bag”
Print “I can’t wait to go to sleep. I’m exhausted!”
Input get_item
Add Sleeping bag to inventory
If inventory has all items and player is in bear den room
Player wins
Else if inventory only has 0-5 items
Player loses
Pseudocode:
INITIALIZE players_room = “Start”
Print “Collect 6 camping items for survival and
avoid getting eaten by a bear. Move
commands: South, North, East, West Add to
Inventory: get ‘item name’”
Loop begin
INPUT the direction
IF players_room is “Start”
IF direction is “South”
Players_room = “Meadow of
flowers”
Else if direction is “East”
Players_room = “Tent”
Else if direction is “West”
Players_room = “Snakes”
Else
OUTPUT “You cannot go that
direction”
Else IF players_room is “Tent”
IF direction is “West”
Players_room = “Start”
Else
OUTPUT “WRONG WAY”
Else IF players_room is “Snakes”
IF direction is “East”
Players_room = “Start”
Else if direction is “South”
Players_room = “Water filter”
Else
OUTPUT “Go another way”
Else IF players_room is “Water filter”
IF direction is “East”
Players_room = “Lighter”
Else if direction is “South”
Players_room = “Food”
Else if direction is “North”
Players_room = “Snakes”
Else
OUTPUT “You must go another direction”
Else IF players_room is “Food”
IF direction is “East”
Players_room = “Spider web”
Else if direction is “North”
Players_room = “Water filter”
Else
OUTPUT “Go another direction”
Else IF players_room is “Spider web”
IF direction is “East”
Players_room = “Swiss army
knife”
Else if direction is “West”
Players_room = “Food”
Else if direction is “North”
Players_room = “Meadow of flowers”
Else
OUTPUT “You must go a different direction”
Else IF players_room is “Swiss army knife”
IF direction is “West”
Players_room = “Spider web”
Else
OUTPUT “Wrong direction”
Else IF players_room is “Meadow of flowers”
IF direction is “East”
Players_room = “Sleeping bag”
Else if direction is “South”
Players_room = “Spider web”
Else if direction is “North”
Players_room = “Start”
Else if direction is “West”
Players_room = “Lighter”
Else
OUTPUT “Frustrating, isn’t it?”
Else IF players_room is “Sleeping bag”
IF direction is “West”
Players_room = “Meadow of
flowers”
Else
OUTPUT “You need to collect all of the items, go another
way”
Else IF players_room is “Bear den”
IF direction is “South”
Players_room = “Sleeping bag”
Else
OUTPUT “Uh oh”
Else IF players_room is “Lighter”
IF direction is “East”
Players_room = “Meadow of
flowers”
Else if direction is “West”
Players_room = “Water filter”
Else
OUTPUT “You may not want to go North or South”
Pseudocode to get an item:
Get an Item
Inventory = “Nothing”
If players_room is “Lighter”
Print “Now I will have fire!”
Input get_item
Add lighter to inventory
If players_room is “Tent”
Print “I have shelter!”
Input get_item
Add Tent to inventory
If players_room is “Food”
Print “I was so hungry and now I can eat!”
Input get_item
Add Food to inventory
If players_room is “Water filter”
Print “Dehydration no more! I have water!”
Input get_item
Add Water filter to inventory
If players_room is “Swiss army knife”
Print “Yes! Tools!”
Input get_item
Add Swiss army knife to inventory
If players_room is “Sleeping bag”
Print “I can’t wait to go to sleep. I’m exhausted!”
Input get_item
Add Sleeping bag to inventory
If inventory has all items and player is in bear den room
Player wins
Else if inventory only has 0-5 items
Player loses