Question: I am trying to make a text-based interactive story in python, but I keep getting this error: AttributeError: 'NoneType' object has no attribute 'get' This
I am trying to make a text-based interactive story in python, but I keep getting this error: AttributeError: 'NoneType' object has no attribute 'get'
This is in Python, and I need help completing this.
Here is the link to the assignment: http://people.scs.carleton.ca/~arunka/courses/comp1005/tutorials/T07.pdf
approach = {'sceneText': "Following the map from the old man in the tavern, you arrive at a large hill," "covered with ancient standing stone forming the shape of a skull if viewed from a high vantage " "point.", \ 'choices': { "Enter the Tomb of Horrors!": "Entrance", "Run Away! (Wuss)": "Runaway" } }
runaway = { 'sceneText': "You wisely choose to turn tail and flee. This was certainly the only way you could have survived such a daunting terror."}
entrance = { 'sceneText': "Digging out the loose earth around the base of the hill, you uncover three large stone doors " "arranged roughly next to each other.", \ 'choices': { "Open the leftmost door.": "Sealed", "Open the central door.": "Hallway", "Open the rightmost door.": "Collapse" } }
sealed = { 'sceneText': "You open the leftmost door and enter into a long, dark hallway. After prroceeding a long way " "inside, you reach a dead end, only to hear the grinding of stone as the entrance slides closed. Stuck in the " "darkness, your thoughts turn to how that was really unfair."}
collapse = { 'sceneText': "You move to open the rightmost door, attempting to pry it open. YOu hear a switch " "activate, and a massive stone slab suspended over the door falls on you, its thud punctuating an abrupt " "end to your adventure."}
hallway = { 'sceneText': "You open the central doors, and see before you a long hallway lined with ancient " "hieroglyphs. On the far wall is a green demon head sculpture with a dark passage in its mouth " "large enough to pass through, and a gateway shrouded in a purple haze. As you approach, you notice " "one of the hierglyphs portrudes slightly from the wall.", \ 'choices': { "Examine the demon's head at the far end of the hallway.":"Demon" , "Pass through the haze-shrouded gateway.":"PurpleHaze", "Inspect the unusual hieroglyphs":"PitTrap" } }
demon = { 'sceneText': "You move up to the Demon Head sculpture on the wall and peer inside. Despite " "bringing your torch up to it, you cannot see any deeper into it. You reach inside " "expecting to find something, but cannot feel a thing. Turns out you lost an arm. You get outta there."}
purplehaze = { 'sceneText': "A chill passes over you as you pass through the haze-shrouded gateway, as you are " "teleported deeper into the dungeon. Expecting the teleport chills to fade, you are memonetarily " "confused, until you realize the cold was not from the teleportation, rather all your belongings are... gone.", \ 'choices': { "Explore your new surroundings.":"darn" } }
darn = { 'sceneText': "As your eyes adjust to your surroundings you find yourself in a sealed concrete " "room with no doors or windows. Ice lines the cracks of the impenetrable walls... " "Well, darn."}
pittrap = { 'sceneText': "You approach the unusual hieroglyphs, but the floor suddenly gives way, and you fall into a pit trap. " "Regaining your bearings at the bottom, you are relieved that you missed all five of the spikes at the bottom. " "You see a door in front of you leading deeper into the dungeon, and one of the spikes has a hidden switch.", \ 'choices': { "Pass through the door ahead of you.":"Gargoyle", "Throw the switch hidden on the spike.":"MoreSpikes" } }
gargoyle = { 'sceneText': "The door at the bottom of the pit trap opens to a secret chamber. You pass into the darkness and the door " "seals behind you. Ahead, you see a gigantic stone gargoyle with four arms. It shudders and comes to life, drawing four " "massive stone blades the size of a person each. I mean at least you can fight this guy right?... right?"}
morespikes = { 'sceneText': "The secret switch causes the floor to give out, dropping you deeper into a second pit trap. You are less " "relieved to find that this time, you did not miss the poisoned spikes, but momementarily, at least."}
def main(): #Part 3 story = {"Approach":approach, "Runaway":runaway, "Entrance":entrance, "Sealed":sealed, "Collapse":collapse, "Hallway":hallway, "Demon":demon, "PurpleHaze":purplehaze, "Damn":damn, "PitTrap":pittrap, "Gargoyle":gargoyle, "MoreSpikes":morespikes} sceneData = story['Approach']
while(True): #.get metehod returns value for the given key print(sceneData.get('sceneText')) print("Choices: ") for choice in sceneData.get('choices'): print(choice) user_choice = input("Select a choice: ") sceneData = story.get(user_choice)
if __name__ == '__main__': main()



approach-'scereToxt': "Follovin the nop fron the ald wan in the tavarn, yau arrie at a large hill, paint." ru'euay " { "scere'Text": "rou wisely Chaese te turn tait nee. This ves certainty the only way you cauta neve " survived such a entrance-{ -sceneText": DWng cut th losse earth aroand the base o, the hill, yau ureever three large stene doors .. arranged rughly mext to each ather. chaices's"Open the teftrost coor.",Open the central door.'Opes the rightnost doar.", nextScere"s[ Seoled" HaLLway "Collapse"1) sealedo( 'scesetext": "You epen the leftnost door ase enter into a long, dark hallway. After prroceedLap leng way . darkness, your thoaghts turn to tow that as really untair activateand a nassive store sla, suspended over the deor falls , you, its t'had punctuating end to yoar adventure. abrupt . halluay _ { 'acercText':"rou tpen the central deora, and ste before you e laag hallMay Lined with ancient Large enoach to pass through, and& gateway shrsuded in a purple hexe. As you approach, you netice e er the hierstyphs pertrudes stigtty fron the aL. chsices'i l'Eonine the eron's hest at the tar erd of the nalbay "Pass through the haze-shrouded gateway lrspect the unusual hieroalyphs.1, .nenseestoenen"..Furple2e", "PitTrap")} dancn cen Text Yos nove up to the Denon Head sculgture on the walt and peer srcide.Despite bringing yeur terch up to it, you carnot see any deeper into it. Yeu reach inside " expacting to fird sanething, but cannot feel a thing. Turns aut yas lost an arn. You get outts thare. parplehaze -aceneText':"& chill passes aver you as you pasa through the hace-ahrauded geteway, as yau are "teleparted deeper Lnte the angean. Cspecting the teleport(h1115 te, you 6re neronetarily confused, until you realize the cold wes rot tron the teleportatien, rather all your belargings are core daen-sceneText": "As your eyes adjust to your surroundings you find yourselih a sealed concrete "vell, dann. pittrspscereText "You oppraech the unasusl hieroglyphs, but the floor suddenty gives wey, and you fall Ieto a pit trep- egaining your bearings at the batton, you are relieved that you nissed all five of the spiks at the tetton. rov seedoor sn rront of you 1eeding deeper into the dangeon,-9rd one gr the bOlkes has 6 hldden 9uLtch,"' \ hidde" chaices' I.Pass through the dcor 3tead of you Throw the switch on the spike.*), 'renscene.16argoyle.. "MareSoLkes garpoyle = {-sceneTest'1 "The door at the botton at the pLT traapens t0.3 secret Chanter-You pass 1nto the darkness and the deer seals behind ,eu. Ahead, you see Sigantic stene gargoyle with reur arns. It shudders " cores to life, drawing four . "nastin ttana blades the "ze of perton each. I mn at least yeu can fight ths guy right? right?" nareapite-( "zceneText.:"The 2ecret zuitch causes the floor to Fave aut, droppang you deeper into a sccond Pit trap. Yo sre le relieved to fird thet this tine, you did not niss the poisored sgikes, but nonerentarily, ot least.") det nelatD scenelsta a storyl 'Approach
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
