Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Text-based adventure game with inventory posing nonetype issues. I'm trying to design a game for a project that uses different 'rooms' and an inventory

image text in transcribedimage text in transcribedimage text in transcribedPython Text-based adventure game with inventory posing "nonetype" issues.

I'm trying to design a game for a project that uses different 'rooms' and an inventory to navigate a player through to the end, and if the player does not have all the items in the inventory then it's game over.

I need help to correct a NoneType error that I believe will come up multiple times if it is coming up in the start.

This is what I have so far:

rooms = { 'Large Clearing': {'South': 'Deer Stand', 'North': 'Hunter Shack 1', 'West': 'Rabbit Den', 'East': 'Woods'}, 'Woods': {'East': 'Large Clearing', 'South': 'Hunter Shack 2'}, 'Hunter Shack 1': {'South': 'Large Clearing'}, 'Hunter Shack 2': {'North': 'Woods', 'South': 'Cliff'}, 'Hunter Shack 3': {'East': 'Rabbit Den'}, 'Rabbit Den': {'East': 'Large Clearing', 'West': 'Hunter Shack 3'}, 'Deer Stand': {'North': 'Large Clearing', 'East': 'Cliff'}, 'Cliff': {'North': 'Hunter Shack 2', 'West': 'Deer Stand'} } def large_clearing_mid(): print("This is where you woke up. There's nothing of importance here, you should keep moving.") move = input()
 def hunter_shack1(): global inventory if 'Axe' not in inventory: print("You see a hunter's shack. There are no footprints in the snow. It does not appear to have had " "visitors") print("in quite some time. You enter. There is a topographic map of the area on the far wall. On it " "are some X's.") print("One is labeled 'HERE', and the other two have names next to them. 'Henry' and 'Wayne'. " "Henry's X is to") print("the South West, and Wayne's X is to the South East. These must be other hunter's shacks marked.") print("You wonder if these men were friendly with each other. You continue to look around.") print("There are some pelts, a couple of decks of cards, binoculars, and an axe above the door.") print("The cards and binoculars don't look very useful. You'll leave them here for the hunter.") print("What do you do?") move = input() if move in ['take axe', 'pick up axe']: print("You take the axe. It looks sturdy and sharp. This can be useful.") inventory = inventory.append('Axe') print("That looks like everything useful. What now?") move = input() elif move not in ['take axe', 'pick up axe']: print("Invalid move. Try again.") move = input() else: print('Invalid move.') move = input() while 'Axe' in inventory: print("This is where you got the axe. The map said there were two shacks in the South East and South " "West.") print("The shack did not offer anything else of use. You should find the other shacks.") print("Where to now?") move = input()
def deer_stand(): global inventory print("A deer stand blends in with the surrounding forest. You understand why the deer are fooled by such a " "construct. Seeing no rifle barrels poking through the gaps or flaps of the stand, you assume it's safe" "to look around. Inside the stand, a single flare gun sits. The hunters must keep this here in case of " "dangerous animals or in the chance that they get injured themselves." "What do you do?") move = input() if move in ['pick up flare gun', 'take flare gun']: print("You pick up the flare gun.") inventory = inventory.append('Flare Gun') move = input() elif move in ['shoot flare gun', 'shoot gun', 'shoot flare']: print("You don't think it would be a good idea to shoot that just yet. You don't know if anybody is near " "enough to see it if you did.") move = input()
while current_room != 'q': while current_room == 'Large Clearing': if move in ['North', 'go North']: current_room = 'Hunter Shack 1' hunter_shack1() elif move in ['South', 'go South']: current_room = 'Deer Stand' elif move in ['West', 'go West']: current_room = 'Rabbit Den' #Fix Me Rabbit Den elif move in ['East', 'go East']: current_room = 'Woods' #Fix Me Woods elif move in ['Q', 'q']: current_room = 'q' else: print("Invalid move.") move = input()
 while current_room == 'Hunter Shack 1': if move in ['South', 'go South']: current_room = 'Large Clearing' large_clearing_mid() elif move in ['East', 'go East', 'West', 'go West', 'South', 'go South', 'North', 'go North']: print("You don't think that way will led you anywhere. How about somewhere else?") move = input() elif move in ['Q', 'q']: current_room = 'q' else: print("Invalid move.") move = input() while current_room == 'Deer Stand': deer_stand()

I cannot get the program to move to another room and run its defined code once the player gets the axe. It produces this error every time:

TypeError: argument of type 'NoneType' is not iterable in reference to 'while 'Axe' in inventory:'

Similarly, I cannot get the main gameplay to operate without the defined "hunter_shack1()" to be in the while current_room = 'Large Clearing' function. I cannot get it to process as it's own when current_room = 'Hunter Shack 1'

Help is greatly appreciated!

main Q 19 A 41 Av S File Edit View Navigate Code Refactor Run Tools Vcs Window Help Expedition_start-main.py Expedition start main.py . I fomain.py MuduleSix Module.py X Expedition > very lit 20 main.py 21 def hunter_shack10: > illi External Lib 22 global inventory Scratches al 23 if 'Axe' not in inventory: 24 print("You see a hunter's shack. There are no footprints in the snow. It does not appear to have had " 25 "visitors") 26 print("in quite some time. You enter. There is a topographic map of the area on the far wall. On it " 27 "are some X's.") 28 5 print("One is labeled 'HERE', and the other two have nanes next to them. 'Henry' and 'Wayne', " 29 "Henry's X is to") 30 print("the South West, and Wayne's X is to the South East. These must be other hunter's shacks marked.") 31 print("You wonder if these men were friendly with each other. You continue to look around.") 32 print("There are some pelts, a couple of decks of cards, binoculars, and an axe above the door.") 33 print("The cards and binoculars don't look very useful. You'll leave them here for the hunter.") 34 print("What do you do?") 35 nove = input() 36 if move in ('take axe', 'pick up axe']; 37 print("You take the axe. It looks sturdy and sharp. This can be useful.") 38 inventory = inventory.append('Axe') 39 print("That looks like everything useful. What now?") 40 A move = Inputo 41 elif move not in ['take axe', 'pick up axe']: print("Invalid move. Try again.") 1413 move = input else: 445 print('Invalid move.') move = input 47 while 'Axe' in Inventory: print("This is where you got the axe. The map said there were two shacks in the South East and South" "West.") 50 print("The shack did not offer anything else of use. You should find the other shacks.") 51 print("Where to now?") 52 a move = input () 53 hunter_shack10 while Axe' in inventory Debug 2 Teminal Python Console E TODO O Problems Event Log 47:30 Python 3.9 (Expedition starti 1 main Q A 41 Av Eile Edit View Navigate Code Befactor Run Jools VCS Window Help Expedition_start-main.py Expedition start main.py femei.py Mudule Six Module.py X Expedition 237 print("Cardinal directions never hurt to start. North, South, East, or West. Where do you go?") > very lit 238 move = input fe main.py 239 while current_room 1= 'q': > Ilh External Lib 240 while current_room == 'Large Clearing': Scratches al 241 if move in ('North', 'go North']: 242 current_room = 'Hunter Shack i hunter_shack1() elit move in ('South', 'go South']: 245 current_room = Deer Stand' 246 elif move in ('West', 'go West']: 247 current_room = 'Rabbit Den' 248 *** status elit move in ('East', 'go East']: 250 current_room = 'Woods' 251 e status 252 elif move in ('9', '4']: 253 current_room = 'q' 2544 5 else: 255 print("Invalid move.") 256 e move = input 257 while current_roon == 'Deer Stand': 258 deer_stando 259 if move in ('North', 'go North']: 260 current_room = 'Large Clearing' 261 a Large_clearing_mido 262 elif move in ['East', 'go East']: 263 current_room = 'Cliff' 264 elif move in [' South', 'go South', 'Yest', 'go West']: 265 print("You get the feeling that direction won't lead anywhere. How about somewhere else?") 266 move = input() 267 elif move in ('Q', 'q']; 268 current_room = 'q 269 else: 270 print("Invalid move.") 271 a move = input hunter_shack10 while Axe' in inventory O Problems Python Console : 1:01 Debug 2. Teminal Event Log 47:30 Python 3.9 (Expedition starti 1 main Q A 42 AV Eile Edit View Navigate Code Befactor Run Jools VCS Window Help Expedition_start-main.py Expedition start main.py - Imain.py Medule:Six Module.py X Expedition 42 print("Invalid move. Try again.") > very lit 43 move = input for main.pylor else: : > External Lib45 print('Invalid move.') Scratches al 46 move = input while 'Axe' in inventory: 48 print("This is where you got the axe. The map said there were two shacks in the South East and South "West.") 50 print("The shack did not offer anything else of use. You should find the other shacks, ") 51 print("Where to now?") 52 e nove = input 53 54 def deer-stando: 55 global inventory 56 print("A deer stand blends in with the surrounding forest. You understand why the deer are fooled by such a " 57 "construct. Seeing na rifle barrels poking through the gaps or flaps of the stand, you assume it's safe" 58 "to look around. Inside the stand, a single flare gun sits. The hunters must keep this here in case of 59 "dangerous animals or in the chance that they get injured themselves." 60 "What do you do?") 61 move - input 62 if move in ('pick up flare gun', 'take flare gun']: 63 print("You pick up the flare gun.") inventory = inventory.append('Flare Gun') a move = inputo 66 elif move in ['shoot flare gun', 'shoot gun', 'shoot are']: 67 print("You don't think it would be a good idea to shoot that just yet. You don't know if anybody is near " 68 "enough to see it if you did.") 69 nove = input () 30 63 71 72 Fidef woods(): global inventory if Axe' not in inventory: print("It looks like some sturdy birches have made themselves at home here. These would make for great " 76 a "firewood, if only you had something to cut one down with.") deerstand E TODO O problems Debug 2 Terminal Python Console Event Log OPEP 8: E302 expected 2 blank lines, found 1 54:18 CRLF UTF-8 4 spaces Python 3.9 (Expedition start main Q 19 A 41 Av S File Edit View Navigate Code Refactor Run Tools Vcs Window Help Expedition_start-main.py Expedition start main.py . I fomain.py MuduleSix Module.py X Expedition > very lit 20 main.py 21 def hunter_shack10: > illi External Lib 22 global inventory Scratches al 23 if 'Axe' not in inventory: 24 print("You see a hunter's shack. There are no footprints in the snow. It does not appear to have had " 25 "visitors") 26 print("in quite some time. You enter. There is a topographic map of the area on the far wall. On it " 27 "are some X's.") 28 5 print("One is labeled 'HERE', and the other two have nanes next to them. 'Henry' and 'Wayne', " 29 "Henry's X is to") 30 print("the South West, and Wayne's X is to the South East. These must be other hunter's shacks marked.") 31 print("You wonder if these men were friendly with each other. You continue to look around.") 32 print("There are some pelts, a couple of decks of cards, binoculars, and an axe above the door.") 33 print("The cards and binoculars don't look very useful. You'll leave them here for the hunter.") 34 print("What do you do?") 35 nove = input() 36 if move in ('take axe', 'pick up axe']; 37 print("You take the axe. It looks sturdy and sharp. This can be useful.") 38 inventory = inventory.append('Axe') 39 print("That looks like everything useful. What now?") 40 A move = Inputo 41 elif move not in ['take axe', 'pick up axe']: print("Invalid move. Try again.") 1413 move = input else: 445 print('Invalid move.') move = input 47 while 'Axe' in Inventory: print("This is where you got the axe. The map said there were two shacks in the South East and South" "West.") 50 print("The shack did not offer anything else of use. You should find the other shacks.") 51 print("Where to now?") 52 a move = input () 53 hunter_shack10 while Axe' in inventory Debug 2 Teminal Python Console E TODO O Problems Event Log 47:30 Python 3.9 (Expedition starti 1 main Q A 41 Av Eile Edit View Navigate Code Befactor Run Jools VCS Window Help Expedition_start-main.py Expedition start main.py femei.py Mudule Six Module.py X Expedition 237 print("Cardinal directions never hurt to start. North, South, East, or West. Where do you go?") > very lit 238 move = input fe main.py 239 while current_room 1= 'q': > Ilh External Lib 240 while current_room == 'Large Clearing': Scratches al 241 if move in ('North', 'go North']: 242 current_room = 'Hunter Shack i hunter_shack1() elit move in ('South', 'go South']: 245 current_room = Deer Stand' 246 elif move in ('West', 'go West']: 247 current_room = 'Rabbit Den' 248 *** status elit move in ('East', 'go East']: 250 current_room = 'Woods' 251 e status 252 elif move in ('9', '4']: 253 current_room = 'q' 2544 5 else: 255 print("Invalid move.") 256 e move = input 257 while current_roon == 'Deer Stand': 258 deer_stando 259 if move in ('North', 'go North']: 260 current_room = 'Large Clearing' 261 a Large_clearing_mido 262 elif move in ['East', 'go East']: 263 current_room = 'Cliff' 264 elif move in [' South', 'go South', 'Yest', 'go West']: 265 print("You get the feeling that direction won't lead anywhere. How about somewhere else?") 266 move = input() 267 elif move in ('Q', 'q']; 268 current_room = 'q 269 else: 270 print("Invalid move.") 271 a move = input hunter_shack10 while Axe' in inventory O Problems Python Console : 1:01 Debug 2. Teminal Event Log 47:30 Python 3.9 (Expedition starti 1 main Q A 42 AV Eile Edit View Navigate Code Befactor Run Jools VCS Window Help Expedition_start-main.py Expedition start main.py - Imain.py Medule:Six Module.py X Expedition 42 print("Invalid move. Try again.") > very lit 43 move = input for main.pylor else: : > External Lib45 print('Invalid move.') Scratches al 46 move = input while 'Axe' in inventory: 48 print("This is where you got the axe. The map said there were two shacks in the South East and South "West.") 50 print("The shack did not offer anything else of use. You should find the other shacks, ") 51 print("Where to now?") 52 e nove = input 53 54 def deer-stando: 55 global inventory 56 print("A deer stand blends in with the surrounding forest. You understand why the deer are fooled by such a " 57 "construct. Seeing na rifle barrels poking through the gaps or flaps of the stand, you assume it's safe" 58 "to look around. Inside the stand, a single flare gun sits. The hunters must keep this here in case of 59 "dangerous animals or in the chance that they get injured themselves." 60 "What do you do?") 61 move - input 62 if move in ('pick up flare gun', 'take flare gun']: 63 print("You pick up the flare gun.") inventory = inventory.append('Flare Gun') a move = inputo 66 elif move in ['shoot flare gun', 'shoot gun', 'shoot are']: 67 print("You don't think it would be a good idea to shoot that just yet. You don't know if anybody is near " 68 "enough to see it if you did.") 69 nove = input () 30 63 71 72 Fidef woods(): global inventory if Axe' not in inventory: print("It looks like some sturdy birches have made themselves at home here. These would make for great " 76 a "firewood, if only you had something to cut one down with.") deerstand E TODO O problems Debug 2 Terminal Python Console Event Log OPEP 8: E302 expected 2 blank lines, found 1 54:18 CRLF UTF-8 4 spaces Python 3.9 (Expedition start

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Influxdb Database A Comprehensive Guide To Learn Influxdb Database

Authors: Cybellium Ltd ,Kris Hermans

1st Edition

B0CNGGWL7B, 979-8867766450

More Books

Students also viewed these Databases questions

Question

A decrease in interest rates will do what to bonds

Answered: 1 week ago