Lädt...

🔧 AttributeError: 'tuple' object has no attribute 'enter'


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Help! I inputted the code below for a game that I'm writing in Python for my daughter. I'm not sure what happened but I received the following error:
Traceback (most recent call last):
File "/home/roberto-padilla/mystuff/ella_game.py", line 193, in
a_game.play()
File "/home/roberto-padilla/mystuff/ella_game.py", line 22, in play
next_scene_name = current_scene.enter()

Can someone please help me? I'm at a loss.

P.S. I realize my code is 193 lines but I thought it would give an idea of what I'm trying to accomplish. Thanks in advance for your help.

`from sys import exit
from random import randint
from textwrap import dedent

class Scene(object):

def enter(self):
    print("This scene is not yet configured.")
    print("Subclass it and implement enter().")
    exit(1)

class Engine(object):

def __init__(self, scene_map):
    self.scene_map = scene_map

def play(self):
    current_scene = self.scene_map.opening_scene()
    last_scene = self.scene_map.next_scene('finished')

    while current_scene != last_scene:
        next_scene_name = current_scene.enter() 
        current_scene = self.scene_map.next_scene(next_scene_name)

    current_scene.enter()

class Death(Scene):

def enter(self):
    if  'outside_house' or 'dark_woods':
        print("Day becomes night and you're devoured by 
             wolves.")
        print("You're dead!  Better luck next time!")
        exit(1)
    elif 'foyer' or 'living_room':
        print("The dog chews your leg off and you bleed to 
             death.")
        print("You're dead!  Better luck next time!") 
        exit(1)
    elif 'cellar':
        print("The dragon burns you to a crisp.")
        print("You're dead!  Better luck next time!")       
        exit(1)
    else:
        print("You are turned into a rodent and eaten by an 
             owl.")
        print("You're dead!  Better luck next time!")
        exit(1)

class OutsideHouse(Scene):

def enter(self, have_bone):
    print(dedent("""
                Welcome to Arcamadius, where magic and 
                creatures exist.  You come to a house in the 
                dark woods.  There is a window on the east wall 
                and a door on the South wall.  The house is 
                surrounded by woods. What would you like to do?
                """))
    action = input("> ")

    if action == 'open window':
        self.open_window()
    elif action == 'open door' and have_bone == True or 
         have_bone == False:
        self.open_door(have_bone)
    else:
        return 'death'

def open_window():
    print(dedent("""
                 You open the window.  It makes a squeaking 
                 noise.  What do you wnat to do now?
                 """ ))
    action = input("> ")

    if action == 'climb into window':
        have_bone = False
        print("You enter the window into the kitchen.")
        return 'kitchen', have_bone
    else:
        print("You just stand there!")
        return 'death'

def open_door(have_bone):
    print("You enter the door into the Foyer")
    return 'foyer', have_bone

class Kitchen (Scene):

def enter(self, have_bone):
    print(dedent("""
                 There is a doorway ahead.  There is also a 
                 table with a bone on it.  What do you wnat to 
                 do?
                 """))
    action = input("> ")

    if action == "go through doorway" and have_bone == True:
        return 'living_room', have_bone
    elif action == "grab bone" and have_bone == False:
        self.grab_bone()
    elif action == "climb out window" and have_bone == True or 
         have_bone == False:
        return 'outside_house', have_bone
    else:
        print("I'm not sure what you are saying.")
        self.enter(self, have_bone)  

def grab_bone():
    print("You grab the bone")
    have_bone = True
    return 'kitchen', have_bone

class Foyer(Scene):

def enter(self, have_bone):
    print(dedent("""
                 A huge dog is staring and growling at you
                 What do you do?
                 """))
    action = input("> ")

    if action == "flee":
        print(dedent("""
                     You managed to get away from the dog 
                     chasing you and the dog goes back into the 
                     house.
                     """))
        return 'outside_house', have_bone
    elif action == "give dog the bone" and have_bone == True:
        self.give_dog_bone()
    elif action == "give dog the bone" and have_bone == False:
        print("you have no bone.")
        return 'death'
    else:
        print("I have no idea what that means.")
        return(self, have_bone)

def give_dog_bone():
    print(dedent("""
                 You give the dog the bone.
                 The dog wants to play.  You play with the dog 
                 for awhile.  Now back to business. The 
                 entrance to the living room is ahead.
                 """))
    return 'living_room'

class LivingRoom(Scene):

def enter(self):
    pass

class DarkWoods(Scene):

def enter(self):
    pass

class Cellar(Scene):

def enter(self):
    pass

class WitchHouse(Scene):

def enter(self):
    pass

class Finished(Scene):

def enter(self):
    pass

class Map(object):
scenes = {
'outside_house': OutsideHouse(),
'kitchen': Kitchen(),
'foyer': Foyer(),
'living_room': LivingRoom(),
'dark_woods': DarkWoods(),
'cellar': Cellar(),
'witch_house': WitchHouse(),
'death': Death(),
'finished': Finished(),
}

def __init__(self, start_scene):
    self.start_scene = start_scene

def next_scene(self, scene_name):
    val = Map.scenes.get(scene_name)
    return val

def opening_scene(self):
    have_bone = False
    return self.next_scene(self.start_scene), have_bone

a_map = Map('outside_house')
a_game = Engine (a_map)
a_game.play()`

...

🔧 AttributeError: 'tuple' object has no attribute 'enter'


📈 93.87 Punkte
🔧 Programmierung

🔧 Answer: AttributeError : 'tuple' has no attribute 'to'


📈 72.46 Punkte
🔧 Programmierung

📰 How to Fix AttributeError: ‘DataFrame’ object has no attribute ‘append’


📈 58.04 Punkte
🔧 AI Nachrichten

📰 Python Tuple, the Whole Truth, and Only the Truth: Hello, Tuple!


📈 44.75 Punkte
🔧 AI Nachrichten

🔧 003 - TSExpert | Transform Tuple's into Object


📈 30.33 Punkte
🔧 Programmierung

🔧 What happens when you Enter a URL in browser & Hit enter


📈 26.9 Punkte
🔧 Programmierung

🔧 Troubleshoot: Update Boto3 'BedrockRuntime' object has no attribute 'start_async_invoke' 🚀


📈 25.37 Punkte
🔧 Programmierung

🔧 What are Attribute Selectors? - [attribute]


📈 24.19 Punkte
🔧 Programmierung

🐧 HTML-Attribute: Ein Überblick über die wichtigsten Attribute


📈 24.19 Punkte
🐧 Server

🔧 JS Object.assign(), Object.create(). Object.defineProperties() Methods.


📈 23.87 Punkte
🔧 Programmierung

🔧 Mastering Object.freeze() and Object.seal() in JavaScript: Controlling Object Mutability


📈 23.87 Punkte
🔧 Programmierung

🔧 Why JavaScript Says "[object Object]" and Not Just "[object]" 🤔


📈 23.87 Punkte
🔧 Programmierung

🕵️ CVE-2022-44108 | pdftojson 94204bb Object.cc Object::copy(Object*) stack-based overflow


📈 23.87 Punkte
🕵️ Sicherheitslücken

🔧 How to check if a tuple is empty in Python?


📈 22.38 Punkte
🔧 Programmierung

🔧 1726. Tuple with Same Product


📈 22.38 Punkte
🔧 Programmierung

🕵️ CVE-2019-25076 | Open vSwitch up to 2.17.2/2.x/3.0.0 Tuple Space Search denial of service


📈 22.38 Punkte
🕵️ Sicherheitslücken

🔧 【ChaoCode】 Swift 基礎篇 8:Tuple 作業


📈 22.38 Punkte
🔧 Programmierung

🔧 C# Language Highlights: Tuple Pattern Matching | On .NET


📈 22.38 Punkte
🔧 Programmierung

🔧 Understanding Tuple Unpacking and Iteration in Python: A Beginner's Guide


📈 22.38 Punkte
🔧 Programmierung

🔧 Understanding Tuple Unpacking and Iteration in Python: A Beginner's Guide


📈 22.38 Punkte
🔧 Programmierung

🐧 Anyone know how Tuple can better support Linux w/ Wayland?


📈 22.38 Punkte
🐧 Linux Tipps

🔧 C# advanced: Tuple Assignments


📈 22.38 Punkte
🔧 Programmierung

🔧 A Quick Guide to Python Tuple Methods with Examples


📈 22.38 Punkte
🔧 Programmierung

🔧 Python - Dictionary, Set, Tuple


📈 22.38 Punkte
🔧 Programmierung

🔧 How to Check if a Tuple is Empty in Python?


📈 22.38 Punkte
🔧 Programmierung

🔧 F# For Dummys - Day 11 Data Structure Tuple


📈 22.38 Punkte
🔧 Programmierung

🔧 This Is Tuple Context Pattern


📈 22.38 Punkte
🔧 Programmierung

📰 Python “Tuple+”: Named Tuples


📈 22.38 Punkte
🔧 AI Nachrichten

🔧 Implementing tuple_find – A Constexpr-Compatible Algorithm for std::tuple in Modern C++


📈 22.38 Punkte
🔧 Programmierung

🐧 Python Tuple count() Method


📈 22.38 Punkte
🐧 Linux Tipps

🔧 Differences Between List and Tuple in Python


📈 22.38 Punkte
🔧 Programmierung

🔧 PostgreSQL Tuple-Level Statistics With pgstattuple


📈 22.38 Punkte
🔧 Programmierung

matomo