Trying to get random riddle to pop up but I get an error instead

As I mentioned before, if Location.next_location is global, then there would be no need to return it via a return statement - it would be visible throughout your script assumming its entirety is within one module (ahem, file). If that is the case, then you can replace this (in the Engine class):

        while current_scene != last_scene:
            next_scene_name = current_scene.enter()

with this:

        while current_scene != last_scene:
            next_scene_name = Location.next_location

I just did the last thing you asked me to do and now when I run the script nothing shows up. Here’s the code:

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

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

class Engine:

    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 = Location.next_location
            current_scene = self.scene_map.next_scene(next_scene_name)

        current_scene.enter()

class Riddle:

    riddle = ' '

class Riddles(Riddle):

    def first_riddle():
        Riddle.riddle = "What is always on its way, but never arrives?"

    def second_riddle():
        Riddle.riddle = "What thrives when you feed it, but dies when you water it?"

    def third_riddle():
        Riddle.riddle = "What do you hold but never keep?  If you take your last, make it deep."

    def fourth_riddle():
        Riddle.riddle = "I don't breathe flames, but I light the night, guiding sailors with my steady sight.  I stand tall on cliffs, where dragons might dwell, but I save lives with every bell.  What am I?"

    def fifth_riddle():
        Riddle.riddle = "They come out at night without being asked yet lost in the day without being stolen.  What are they?"

class Location:

    death_location = ' '
    next_location = ' '

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

class Start(Location):
      
    def enter(self):
        Location.death_location ='start'
        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("> (open window, open door) ")

        if action == 'open window':
            print(dedent("""
                        You open the window.  It makes a squeaking noise.
                        What do you want to do now?
                        """ ))
            action = input("> (climb into window) ")

            if action == 'climb into window':
                print("You enter the window into the kitchen.")
                Location.next_location = 'kitchen'
            else:
                print("You just stand there!")
                Location.next_location = 'death'
            
        elif action == 'open door':
            print("You enter the door into the Foyer")
            Location.next_location = 'foyer'
        else:
            Location.next_location = 'death'

class OutsideHouseWithoutBone(Location):

    def enter(self):
        Location.death_location = 'outside_house_without_bone'
        have_bone = False
        print(dedent("""
                    You are at 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("> (open window, open door) ")

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

            if action == 'climb into window':
                print("You enter the window into the kitchen.")
                Location.next_location = 'kitchen'
            else:
                print("You just stand there!")
                Location.next_location = 'death'
        elif action == 'open door':
            print("You enter the door into the Foyer")
            Location.next_location = 'foyer'
        else:
            Location.next_location = 'death'
        
class OutsideHouseWithBone(Location):
    
    def enter(self):
        Location.death_location  = 'outside_house_with_bone'
        have_bone = True
        print(dedent("""
                    You are at a house in the dark woods.
                    There is an open window on the east wall and a door on the
                    South wall.  The house is surrounded by woods. You are 
                    carrying a bone.  What would you like to do?
                    """)) 
        action = input("> (climb into window, open door) ")

        if action == 'climb into window':
                print("You enter the window into the kitchen.")
                Location.next_location = 'kitchen_with_bone'
        elif action == 'open door':
            print("You enter the door into the Foyer")
            Location.next_location = 'foyer_with_bone'
        else:
            Location.next_location = 'death'

        
class Kitchen (Location):

    def enter(self):
        have_bone = False
        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("> (go through doorway, grab bone, climb out window) ")

        if action == "go through doorway" and have_bone == True:
            Location.next_location = 'living_room'
        elif action == "grab bone" and have_bone == False:
            print("You grab the bone")
            Location.next_location = 'kitchen_with_bone'
        elif action == "climb out window":
            Location.next_location = 'outside_house_without_bone'
        else:
            print("I'm not sure what you are saying.")
            self.enter(self) 
            
class KitchenWithBone(Location):

    def enter(self):
        Location.location = 'kitchen_with_bone'
        have_bone = True
        print(dedent("""
                     There is a doorway ahead.  There is also an empty
                     table.  What do you wnat to do?
                     """))
        action = input("> (go through doorway, climb out window)")

        if action == "go through doorway" and have_bone == True:
            Location.next_location = 'living_room'
        elif action == "climb out window":
            Location.next_location = 'outside_house_with_bone'
        else:
            print("I'm not sure what you are saying.")
            self.enter(self)    

class Foyer(Location):
    
    def enter(self):
        Location.death_location = 'foyer'
        have_bone = False
        print(dedent("""
                     A huge dog is staring and growling at you
                     What do you do?
                     """))
        action = input("> (flee, give dog the bone) ")

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

class FoyerWithBone(Location):

    def enter(self):
        have_bone = True
        print(dedent("""
                     A huge dog is staring and growling at you and you are
                     carrying a bone.  What do you do?
                     """))
        action = input("> (flee, give dog the bone) ")

        if action == "flee":
            print(dedent("""
                         You managed to get away from the dog chasing you and the
                         dog goes back into the house.
                         """))
            Location.next_location = 'outside_house_with_bone'
        elif action == "give dog the bone" and have_bone == True:
            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.
                        """))
            Location.next_location = 'living_room'
        else:
            print("I have no idea what that means.")
            Location.next_location = 'foyer_with_bone'

class LivingRoom(Location):

    def enter(self):
        Location.death_location = 'living_room'
        have_bone = True
        print(dedent("""
                     You are in the living room.  There is a trap door in the floor.
                     There is a mantle with an electric lantern on it.  A huge dog
                     is staring and growling at you.  You are carrying a bone.  What
                     would you like to do?
                     """))
        action = input("> (give dog the bone) ")

        if action == "give dog the bone" and have_bone == True:
            print(dedent("""
                        You give the dog the bone.
                        The dog wants to play.  You play with the dog for awhile.
                        The dog goes asleep. You are in the living room.  There is
                        a trap door in the floor.  There is a mantle with an electric
                        lantern on it.  What would you like to do?
                        """))
            action = input("> ( grab lantern)")

            if  action == "grab lantern":
                print(dedent("""
                             You grab the lantern and turn it on. You are in the
                             living room.  There is a trap door in the floor.
                             There is an empty mantle.  You open the trap door.
                             """))
                Location.next_location = 'cellar'
            else:
                print(dedent("""
                             The dog wakes up from its slumber and is hungry.  It 
                             growls and snarls at you.
                             """))
                Location.next_location = 'death'
        else:
            Location.next_location = 'death'

class DarkWoods(Location):
    
    def enter(self):
        pass

class Cellar(Location):

    def enter(self):
        Location.death_location = 'cellar'
        print(dedent("""
                     You open the open the door to the cellar and a foul
                     stench is coming from the darkness.  You head into 
                     the cellar.  In the corner, you see a dragon laying
                     on a bed of gold.  On top of the gold is a nest and
                     in the nest is five dragon eggs What would you like
                     to do?
                     """))
        action = input("> (grab some gold, grab an egg, approach dragon) ")

        if action == "grab some gold":
            print(dedent("""
                         The dragon awakens in a fury and says, 'How dare 
                         thee take my gold!  For that you will perish!'
                         """))
            Location.next_location = 'death'
        elif action == "grab an egg":
            print(dedent("""
                         The dragon awakens in a fury and says, 'How dare 
                         thee take one of my eggs!  For that you will perish!'
                         """))
            Location.next_location = 'death'
        elif action == "approach dragon":
            print(dedent("""
                         You approach the dragon and ask the dragon, 'How may I
                         obtain an egg from you?'  The dragon says, '
                         You must first answer a riddle.  Then you will get an egg'
                         """))
            Location.next_location = 'cellar'
        else:
            print("I'm not sure what you mean.")
            Location.next_location = 'cellar'
        
            riddle_number = f"{randint(1,5)}"
            guesses = 1

            if riddle_number == 1:
                print(Riddles.first_riddle())
                guess = input("[your answer]> ")
                answer = "Tomorrow"
            elif riddle_number == 2:
                print(Riddles.second_riddle())
                guess = input("[your answer]> ")
                answer = "Fire"
            elif riddle_number == 3:
                print(Riddles.third_riddle())
                guess = input("[your answer]> ")
                answer = "A breath of air"
            elif riddle_number == 4:
                print(Riddles.fourth_riddle())
                guess = input("[your answer]> ")
                answer = "A lighthouse"
            else:
                print(Riddles.fifth_riddle())
                guess = input("[your answer]> ")
                answer = "Stars"

            while guess != answer and guesses < 3:
                print("Try again!")
                guesses += 1
                guess = input("[your answer]> ")

            if guess == answer:
                print(dedent("""
                             You have answered correctly.  You carefully chooose
                             an egg.  The dragon speaks some magic words and you 
                             are teleported to the Dark Woods.
                             """))
                Location.next_location = 'dark_woods'

class WitchHouse(Location):

    def enter(self):
        pass

class Finished(Location):

    def enter(self):
        pass

class Map:
    scenes = {
        'start': Start(),
        'outside_house_without_bone': OutsideHouseWithoutBone(),
        'outside_house_with_bone': OutsideHouseWithBone(),
        'kitchen': Kitchen(),
        'kitchen_with_bone': KitchenWithBone(),
        'foyer': Foyer(),
        "foyer_with_bone": FoyerWithBone(),
        '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)

a_map = Map('start')
a_game = Engine (a_map)
try:
    a_game.play()
except KeyboardInterrupt:
    pass

In this part:

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

        current_scene.enter()

It looks like the last line (current_scene.enter()) should also be inside of the while loop.

Hello,

ok, here is the updated version. I have simplified it greatly as I have removed the Map class since it was merged with the Engine class. By combining these two classes and making use of the global variable Location.next_location, there is no need to make function calls via instance variables and nested function calls via inheritance. The Location.next_locati on serves as the key for the scenes dictionary. Thus, the Location.next_location determines the current method being executed.

I have also updated other areas of the script whereby I removed unnecessary self object instance variables in the cases of static methods. Please reference the material on the matter so that you understand the theory behind it.

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

class Scene:

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

class Riddle:
    riddle = ' '

class Riddles(Riddle):

    @staticmethod
    def first_riddle():
        Riddle.riddle = "What is always on its way, but never arrives?"

    @staticmethod
    def second_riddle():
        Riddle.riddle = "What thrives when you feed it, but dies when you water it?"

    @staticmethod
    def third_riddle():
        Riddle.riddle = "What do you hold but never keep?  If you take your last, make it deep."

    @staticmethod
    def fourth_riddle():
        Riddle.riddle = "I don't breathe flames, but I light the night, guiding sailors with my steady sight.  I stand tall on cliffs, where dragons might dwell, but I save lives with every bell.  What am I?"

    @staticmethod
    def fifth_riddle():
        Riddle.riddle = "They come out at night without being asked yet lost in the day without being stolen.  What are they?"


class Location:

    death_location = ' '
    next_location = ' '

class Death(Location):

    @staticmethod
    def enter():

        if Location.death_location in ('start', 'dark_woods', 'outside_house_without_bone', 'outside_house_with_bone'):
            print("Day becomes night and you're devoured by wolves.")

        elif Location.death_location in ('foyer', 'living_room'):
            print("The dog chews your leg off and you bleed to death.")

        elif Location.death_location == 'cellar':
            print("The dragon burns you to a crisp.")

        else:
            print("You are turned into a rodent and eaten by an owl.")

        print("You're dead!  Better luck next time!")
        exit(0)


class Start(Location):

    @staticmethod
    def enter():
        Location.death_location = 'start'
        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("> (open window, open door) ")

        if action == 'open window':
            print(dedent("""
                        You open the window.  It makes a squeaking noise.
                        What do you want to do now?
                        """))
            action = input("> (climb into window) ")

            if action == 'climb into window':
                print("You enter the window into the kitchen.")
                Location.next_location = 'kitchen'
            else:
                print("You just stand there!")
                Location.next_location = 'death'

        elif action == 'open door':
            print("You enter the door into the Foyer")
            Location.next_location = 'foyer'
        else:
            Location.next_location = 'death'


class OutsideHouseWithoutBone(Location):

    @staticmethod
    def enter():
        Location.death_location = 'outside_house_without_bone'
        have_bone = False
        print(dedent("""
                    You are at 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("> (open window, open door) ")

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

            if action == 'climb into window':
                print("You enter the window into the kitchen.")
                Location.next_location = 'kitchen'
            else:
                print("You just stand there!")
                Location.next_location = 'death'
        elif action == 'open door':
            print("You enter the door into the Foyer")
            Location.next_location = 'foyer'
        else:
            Location.next_location = 'death'

class OutsideHouseWithBone(Location):

    @staticmethod
    def enter():
        Location.death_location = 'outside_house_with_bone'
        have_bone = True
        print(dedent("""
                    You are at a house in the dark woods.
                    There is an open window on the east wall and a door on the
                    South wall.  The house is surrounded by woods. You are 
                    carrying a bone.  What would you like to do?
                    """))
        action = input("> (climb into window, open door) ")

        if action == 'climb into window':
            print("You enter the window into the kitchen.")
            Location.next_location = 'kitchen_with_bone'
        elif action == 'open door':
            print("You enter the door into the Foyer")
            Location.next_location = 'foyer_with_bone'
        else:
            Location.next_location = 'death'


class Kitchen(Location):

    @staticmethod
    def enter():
        have_bone = False
        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("> (go through doorway, grab bone, climb out window) ")

        if action == "go through doorway" and have_bone == True:
            Location.next_location = 'living_room'
        elif action == "grab bone" and have_bone == False:
            print("You grab the bone")
            Location.next_location = 'kitchen_with_bone'
        elif action == "climb out window":
            Location.next_location = 'outside_house_without_bone'
        else:
            print("I'm not sure what you are saying.")
            # self.enter(self)


class KitchenWithBone(Location):

    @staticmethod
    def enter():
        Location.location = 'kitchen_with_bone'
        have_bone = True
        print(dedent("""
                     There is a doorway ahead.  There is also an empty
                     table.  What do you wnat to do?
                     """))
        action = input("> (go through doorway, climb out window)")

        if action == "go through doorway" and have_bone == True:
            Location.next_location = 'living_room'
        elif action == "climb out window":
            Location.next_location = 'outside_house_with_bone'
        else:
            print("I'm not sure what you are saying.")
            # self.enter(self)


class Foyer(Location):

    @staticmethod
    def enter():
        Location.death_location = 'foyer'
        have_bone = False
        print(dedent("""
                     A huge dog is staring and growling at you
                     What do you do?
                     """))
        action = input("> (flee, give dog the bone) ")

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


class FoyerWithBone(Location):

    @staticmethod
    def enter():
        have_bone = True
        print(dedent("""
                     A huge dog is staring and growling at you and you are
                     carrying a bone.  What do you do?
                     """))
        action = input("> (flee, give dog the bone) ")

        if action == "flee":
            print(dedent("""
                         You managed to get away from the dog chasing you and the
                         dog goes back into the house.
                         """))
            Location.next_location = 'outside_house_with_bone'
        elif action == "give dog the bone" and have_bone == True:
            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.
                        """))
            Location.next_location = 'living_room'
        else:
            print("I have no idea what that means.")
            Location.next_location = 'foyer_with_bone'


class LivingRoom(Location):

    @staticmethod
    def enter():
        Location.death_location = 'living_room'
        have_bone = True
        print(dedent("""
                     You are in the living room.  There is a trap door in the floor.
                     There is a mantle with an electric lantern on it.  A huge dog
                     is staring and growling at you.  You are carrying a bone.  What
                     would you like to do?
                     """))
        action = input("> (give dog the bone) ")

        if action == "give dog the bone" and have_bone == True:
            print(dedent("""
                        You give the dog the bone.
                        The dog wants to play.  You play with the dog for awhile.
                        The dog goes asleep. You are in the living room.  There is
                        a trap door in the floor.  There is a mantle with an electric
                        lantern on it.  What would you like to do?
                        """))
            action = input("> ( grab lantern)")

            if action == "grab lantern":
                print(dedent("""
                             You grab the lantern and turn it on. You are in the
                             living room.  There is a trap door in the floor.
                             There is an empty mantle.  You open the trap door.
                             """))
                Location.next_location = 'cellar'
            else:
                print(dedent("""
                             The dog wakes up from its slumber and is hungry.  It 
                             growls and snarls at you.
                             """))
                Location.next_location = 'death'
        else:
            Location.next_location = 'death'


class DarkWoods(Location):

    @staticmethod
    def enter():
        pass


class Cellar(Location):

    @staticmethod
    def enter():
        Location.death_location = 'cellar'
        print(dedent("""
                     You open the open the door to the cellar and a foul
                     stench is coming from the darkness.  You head into 
                     the cellar.  In the corner, you see a dragon laying
                     on a bed of gold.  On top of the gold is a nest and
                     in the nest is five dragon eggs What would you like
                     to do?
                     """))
        action = input("> (grab some gold, grab an egg, approach dragon) ")

        if action == "grab some gold":
            print(dedent("""
                         The dragon awakens in a fury and says, 'How dare 
                         thee take my gold!  For that you will perish!'
                         """))
            Location.next_location = 'death'
        elif action == "grab an egg":
            print(dedent("""
                         The dragon awakens in a fury and says, 'How dare 
                         thee take one of my eggs!  For that you will perish!'
                         """))
            Location.next_location = 'death'
        elif action == "approach dragon":
            print(dedent("""
                         You approach the dragon and ask the dragon, 'How may I
                         obtain an egg from you?'  The dragon says, '
                         You must first answer a riddle.  Then you will get an egg'
                         """))
            Location.next_location = 'cellar'
        else:
            print("I'm not sure what you mean.")
            Location.next_location = 'cellar'

            riddle_number = f"{randint(1, 5)}"
            guesses = 1

            if riddle_number == 1:
                print(Riddles.first_riddle())
                guess = input("[your answer]> ")
                answer = "Tomorrow"
            elif riddle_number == 2:
                print(Riddles.second_riddle())
                guess = input("[your answer]> ")
                answer = "Fire"
            elif riddle_number == 3:
                print(Riddles.third_riddle())
                guess = input("[your answer]> ")
                answer = "A breath of air"
            elif riddle_number == 4:
                print(Riddles.fourth_riddle())
                guess = input("[your answer]> ")
                answer = "A lighthouse"
            else:
                print(Riddles.fifth_riddle())
                guess = input("[your answer]> ")
                answer = "Stars"

            while guess != answer and guesses < 3:
                print("Try again!")
                guesses += 1
                guess = input("[your answer]> ")

            if guess == answer:
                print(dedent("""
                             You have answered correctly.  You carefully chooose
                             an egg.  The dragon speaks some magic words and you 
                             are teleported to the Dark Woods.
                             """))
                Location.next_location = 'dark_woods'

class WitchHouse(Location):

    @staticmethod
    def enter():
        pass

class Finished(Location):

    @staticmethod
    def enter():
        pass

class Engine(Location):

    # Function dictionary
    scenes = {
        'start': Start(),
        'outside_house_without_bone': OutsideHouseWithoutBone(),
        'outside_house_with_bone': OutsideHouseWithBone(),
        'kitchen': Kitchen(),
        'kitchen_with_bone': KitchenWithBone(),
        'foyer': Foyer(),
        "foyer_with_bone": FoyerWithBone(),
        'living_room': LivingRoom(),
        'dark_woods': DarkWoods(),
        'cellar': Cellar(),
        'witch_house': WitchHouse(),
        'death': Death(),
        'finished': Finished(),
    }

    @staticmethod
    def play(start):
        Location.next_location = start

        while True: # Start game
            Engine.scenes[Location.next_location].enter()

try:
    Engine.play('start')

except KeyboardInterrupt:
    pass

For the print menus, consider the option of giving the user the option of just requiring them to enter a number or a letter as it will greatly simplify the user experience. There is prone to be typos. If that is the case, there is potential for unknown unintended consequences and will require you to add additional layers of code to catch typos.

This is an example of the current version:

action = input("> (open window, open door) ")

Here is an alternative. Notice how it is much easier to deal with from a user point of view. No typing required and less potential for typos.

action = input('\nPlayer options:'
               '\n--------------'
               '\n1. Open window?  Enter "1"'
               '\n2. Open door?    Enter "2"')

Good luck!

Ok, so I retyped the script with everything you suggested. Now back to the original question, I was wondering what to do with the scipt in the Cellar class to get a random riddle to display. I’m not certain what you were saying before about this topic, so if you could explain it differently, I would appreciate it. Thank you. Here’s the code for the Cellar class:

class Cellar(Location):

    def enter(self):
        Location.death_location = 'cellar'
        print(dedent("""
                     You open the open the door to the cellar and a foul
                     stench is coming from the darkness.  You head into 
                     the cellar.  In the corner, you see a dragon laying
                     on a bed of gold.  On top of the gold is a nest and
                     in the nest is five dragon eggs What would you like
                     to do?
                     """))
        action = input("> (grab some gold, grab an egg, approach dragon) ")

        if action == "grab some gold":
            print(dedent("""
                         The dragon awakens in a fury and says, 'How dare 
                         thee take my gold!  For that you will perish!'
                         """))
            Location.next_location = 'death'
        elif action == "grab an egg":
            print(dedent("""
                         The dragon awakens in a fury and says, 'How dare 
                         thee take one of my eggs!  For that you will perish!'
                         """))
            Location.next_location = 'death'
        elif action == "approach dragon":
            print(dedent("""
                         You approach the dragon and ask the dragon, 'How may I
                         obtain an egg from you?'  The dragon says, '
                         You must first answer a riddle.  Then you will get an egg'
                         """))
            riddle_number = f"{randint(1,5)}"
            guesses = 1

            if riddle_number == 1:
                print(Riddles.first_riddle)
                guess = input("[your answer]> ")
                answer = "Tomorrow"
            elif riddle_number == 2:
                print(Riddles.second_riddle)
                guess = input("[your answer]> ")
                answer = "Fire"
            elif riddle_number == 3:
                print(Riddles.third_riddle)
                guess = input("[your answer]> ")
                answer = "A breath of air"
            elif riddle_number == 4:
                print(Riddles.fourth_riddle)
                guess = input("[your answer]> ")
                answer = "A lighthouse"
            else:
                print(Riddles.fifth_riddle)
                guess = input("[your answer]> ")
                answer = "Stars"

            while guess != answer and guesses < 3:
                print("Try again!")
                guesses += 1
                guess = input("[your answer]> ")

            if guess == answer:
                print(dedent("""
                             You have answered correctly.  You carefully chooose
                             an egg.  The dragon speaks some magic words and you 
                             are teleported to the Dark Woods.
                             """))
                Location.next_location = 'dark_woods'
        else:
            print("I'm not sure what you mean.")
            Location.next_location = 'cellar'

Here’s the output:
You approach the dragon and ask the dragon, ‘How may I
obtain an egg from you?’ The dragon says, ’
You must first answer a riddle. Then you will get an egg’

<function Riddles.fifth_riddle at 0x75b4d0f20220>
[your answer]> Stars

You have answered correctly. You carefully chooose
an egg. The dragon speaks some magic words and you
are teleported to the Dark Woods.

Why is it always going to ask the fifth riddle and how can I fix that along with printing the riddle?

In this line:

            riddle_number = f"{randint(1,5)}"

You are assigning a string to riddle_number. But later, in this line:

            if riddle_number == 1:

You compare it to an integer, so it will never match. Likewise for the rest of the riddles, until you get to the last one, which only has else:, so that is the one that will always match. Instead of assigning a string, just assign the result of randint, like so:

            riddle_number = randint(1,5)

You’ve written:

                print(Riddles.fifth_riddle)

But fifth_riddle is a function, as the output shows. You should make sure to call the function, like so:

                print(Riddles.fifth_riddle())

Hello,

the reason why a riddle is not printed is because the riddle functions in the Riddle class are missing a return statement. Note that if a function does not have an explicit return statement, then a None is returned by default.

Here is a small test script. Both functions are identical except for the added return statement in the second function. Please run the script and observe the results.

def some_function_1():
    var1 = 55

print(some_function_1())


def some_function_2():
    var2 = 55
    return var2   # Added return statement here

print(some_function_2())

The output is:

None
55

So, reviewing the Riddle class, you will see that all of the functions are missing a return statement, and thus not returnign the Riddle.riddle string variables.

Here are the two classes in question (I have added the return statements to the functions):


class Riddle:
    riddle = ' '

class Riddles(Riddle):

    @staticmethod
    def first_riddle():
        Riddle.riddle = "What is always on its way, but never arrives?"
        return  Riddle.riddle

    @staticmethod
    def second_riddle():
        Riddle.riddle = "What thrives when you feed it, but dies when you water it?"
        return  Riddle.riddle

    @staticmethod
    def third_riddle():
        Riddle.riddle = "What do you hold but never keep?  If you take your last, make it deep."
        return  Riddle.riddle

    @staticmethod
    def fourth_riddle():
        Riddle.riddle = "I don't breathe flames, but I light the night, guiding sailors with my steady sight.  I stand tall on cliffs, where dragons might dwell, but I save lives with every bell.  What am I?"
        return  Riddle.riddle

    @staticmethod
    def fifth_riddle():
        Riddle.riddle = "They come out at night without being asked yet lost in the day without being stolen.  What are they?"
        return  Riddle.riddle


class Cellar(Location):

    @staticmethod
    def enter():

        Location.death_location = 'cellar'

        print(dedent("""
                     You open the open the door to the cellar and a foul
                     stench is coming from the darkness.  You head into 
                     the cellar.  In the corner, you see a dragon laying
                     on a bed of gold.  On top of the gold is a nest and
                     in the nest is five dragon eggs What would you like
                     to do?
                     """))
        action = input("> (grab some gold, grab an egg, approach dragon) ")

        if action == "grab some gold":
            print(dedent("""
                         The dragon awakens in a fury and says, 'How dare 
                         thee take my gold!  For that you will perish!'
                         """))
            Location.next_location = 'death'

        elif action == "grab an egg":
            print(dedent("""
                         The dragon awakens in a fury and says, 'How dare 
                         thee take one of my eggs!  For that you will perish!'
                         """))
            Location.next_location = 'death'

        elif action == "approach dragon":
            print(dedent("""
                         You approach the dragon and ask the dragon, 'How may I
                         obtain an egg from you?'  The dragon says, '
                         You must first answer a riddle.  Then you will get an egg'
                         """))

            riddle_number = riddle_number = randint(1,5)  # adde this from @jrivers
            print('The value of riddle_number is:', riddle_number)
            guesses = 1

            if riddle_number == 1:

                print(Riddles.first_riddle())
                guess = input("[your answer]> ")
                answer = "Tomorrow"

            elif riddle_number == 2:
                print(Riddles.second_riddle())
                guess = input("[your answer]> ")
                answer = "Fire"

            elif riddle_number == 3:

                print(Riddles.third_riddle())
                guess = input("[your answer]> ")
                answer = "A breath of air"

            elif riddle_number == 4:

                print(Riddles.fourth_riddle())
                guess = input("[your answer]> ")
                answer = "A lighthouse"

            else:
                print(Riddles.fifth_riddle())
                guess = input("[your answer]> ")
                answer = "Stars"

            while guess != answer and guesses < 3:
                print("Try again!")
                guesses += 1
                guess = input("[your answer]> ")

            if guess == answer:
                print(dedent("""
                             You have answered correctly.  You carefully chooose
                             an egg.  The dragon speaks some magic words and you 
                             are teleported to the Dark Woods.
                             """))
                Location.next_location = 'dark_woods'

        else:
                print("I'm not sure what you mean.")
                Location.next_location = 'cellar'

try:
    Cellar.enter()
except KeyboardInterrupt:
    pass

And yes, as @jrivers pointed out, the value of riggle_number is a type str and not a type int. You have to obtain the value via, as he pointed out:

riddle_number = randint(1,5)

By the way, if the riddle print statements are not going to be printed anywhere else in your script (exclusively in Cellar class), you can get rid of the Riddle and Riddles classes and just print the riddle strings in the Cellar class.

I think you use classes quite abusively. The idea of a class is that it should group together similar objects, but it seems you use a class for each object… Instead of class SecondRiddle you should use something like Riddle(number=2).

Instead of having a class with a function for each riddle, you could just have one class to represent riddles, followed by a list of riddles, like this:

Riddle = collections.namedtuple('Riddle', ('question', 'answer'))
riddles = (
    Riddle(
        question = "What is always on its way, but never arrives?",
        answer = "Tomorrow"
        ),
    Riddle(
        question = "What thrives when you feed it, but dies when you water it?",
        answer = "Fire"
        ),
    Riddle(
        question = "What do you hold but never keep?  If you take your last, make it deep.",
        answer = "A breath of air"
        ),
    Riddle(
        question = "I don't breathe flames, but I light the night, guiding sailors with my steady sight.  I stand tall on cliffs, where dragons might dwell, but I save lives with every bell.  What am I?",
        answer = "A lighthouse"
        ),
    Riddle(
        question = "They come out at night without being asked yet lost in the day without being stolen.  What are they?",
        answer = "Stars"
        ),
    )

This also keeps the riddles together with their answers in the code. Then, in the part where you want to ask the riddle, you could write:

question, answer = random.choice(riddles)
print(question)
guess = input("[your answer]> ")

guesses = 1
while guess != answer and guesses < 3:
    # and so on, as in your original code

This way you could dispense with the if–elif–else statement, with a branch for every riddle. The if–elif–else statement might work fine when you have only 5 riddles, but imagine later you want to have 100 different riddles—that would get quite unwieldy.

And, by keeping the questions and answers together, you’ll avoid mixing up the wrong questions with the wrong answers, which could easily happen when there’s a large distance between them. This way, any changes you want to make to the riddles, you’ll only need to change it one place in your code.

1 Like

As a follow up, as I stated before, you may delete the Riddle and Riddles classes altogether and include the print statements within the Cellar class. I have modified the Cellar class whereby the riddles and answers are grouped into their own dictionaries. Then, once the random integer number is obtained, it is used to key the dictionaries to provide the corresponding riddle and answer. This greatly simplies the script as well as making it less verbose.

class Cellar(Location):

    @staticmethod
    def enter():
        Location.death_location = 'cellar'
        print(dedent("""
                     You open the open the door to the cellar and a foul
                     stench is coming from the darkness.  You head into
                     the cellar.  In the corner, you see a dragon laying
                     on a bed of gold.  On top of the gold is a nest and
                     in the nest is five dragon eggs What would you like
                     to do?
                     """))

        action = int(input('\nMenu Options:'
                           '\n-------------'
                           '\n1. grab some gold:  Type 1 and hit Enter.'
                           '\n2. grab and egg:    Type 2 and hit Enter.'
                           '\n3. approach dragon: Type 3 and hit Enter\n'))

        actions = {1: ['\nThe dragon awakens in a fury and says: How dare'
                       '\nthee take my gold!  For that you will perish!',
                       "death"],

                   2: ['\nThe dragon awakens in a fury and says: How dare'
                       '\nthee take one of my eggs!  For that you will perish!',
                       "death"],

                   3: ['\nYou approach the dragon and ask the dragon: \nHow may I'
                       'obtain an egg from you?  The dragon says: '
                       '\nYou must first answer a riddle.  Then you will get an egg.',
                       "cellar"]
                   }

        if action <= len(actions):

            print(actions[action][0])
            Location.location = actions[action][1]

        else:

            print("I'm not sure what you mean.")
            Location.next_location = 'cellar'

            # Create dictionary of riddles
            riddles = { 1: "What is always on its way, but never arrives?",
                        2: "What thrives when you feed it, but dies when you water it?",
                        3: "What do you hold but never keep?  If you take your last, make it deep.",
                        4: "I don't breathe flames, but I light the night, guiding sailors with my steady sight.  "
                           "\nI stand tall on cliffs, where dragons might dwell, but I save lives with every bell.  What am I?",
                        5: "They come out at night without being asked yet lost in the day without being stolen.  What are they?"
                       }
            # Create dictionary of answers
            answers = { 1: "Tomorrow",
                        2: "Fire",
                        3: "A breath of air",
                        4: "A lighthouse",
                        5: "Stars"
                       }

            import random as rd
            riddle_number = rd.randint(1, len(riddles))
            guesses = 1

            if riddle_number <= len(riddles):

                print(riddles[riddle_number])
                answer = answers[riddle_number]
                guess = input("[your answer]> ")

            if guess == answer:
                print(dedent("""
                             You have answered correctly.  You carefully choose
                             an egg.  The dragon speaks some magic words and you
                             are teleported to the Dark Woods.
                             """))

            while guess != answer and guesses < 3:
                print("Try again!")
                guesses += 1
                guess = input("[your answer]> ")

            if guess == answer:
                print(dedent("""
                             You have answered correctly.  You carefully choose
                             an egg.  The dragon speaks some magic words and you
                             are teleported to the Dark Woods.
                             """))
                Location.next_location = 'dark_woods'

If you would like to add additional riddles and answers, you can simply add them at the tail end of both dictionaries without any additional modification to the script.

BTW my daughter wants the game to ask open- ended questions, because it allows her to think about the answer. I happen to agree with her. Besides, the original text-based games had open ended questions. Matter of preference really. But I do appreciate all the help you have been. Thanks again.