I'm new to coding, using sololearn and trying to make some changes to the code in a simple python game to do with injuring a goblin. It takes two words, the first is the verb and there are a few options of what you can do. Then there is the noun, and only class of character here is the goblin.
Two things I am stuck on:
I am wanting to print out the goblin's health and then the comment
(e.g. "Tis but a flesh wound") after each time he is hit.
I was also wanting to add a generic verb that allows for other types of injury; stroke, stab, and have one class that logs that as
a hit too.
Appreciate any feedback
#simple game
class GameObject:
class_name = ""
desc = ""
objects = {}
def __init__(self, name):
self.name = name
GameObject.objects[self.class_name] = self
def get_desc(self):
return self.class_name + "\n" + self.desc
class Goblin(GameObject):
def __init__(self, name):
self.class_name = "goblin"
self.health = 3
self._desc = "A foul creature"
super().__init__(name)
#property
def desc(self):
if self.health >= 3:
return self._desc
elif self.health == 2:
health_line = "Tis but a flesh wound"
elif self.health == 1:
health_line = "He's not looking good"
elif self.health <= 0:
health_line = "It is dead"
return self._desc + "\n" + health_line
#desc.setter
def desc(self, value):
self._desc = value
def hit(noun):
if noun in GameObject.objects:
thing = GameObject.objects[noun]
if type(thing) == Goblin:
thing.health = thing.health -1
print(thing.health)
if thing.health <= 0:
msg = "You killed the Goblin"
else:
msg = "You hit the {}".format(thing.class_name)
else:
msg = "There is no {} here".format(noun)
return msg
goblin = Goblin("Gobbly")
def examine(noun):
if noun in GameObject.objects:
return GameObject.objects[noun].get_desc()
else:
return "What do you mean, there is no {} here".format(noun)
def get_input():
command = input(": ").split()
verb_word = command[0]
if verb_word in verb_dict:
verb = verb_dict[verb_word]
else:
print("Unrecognised verb {}, not in our incredibly limited dictionary".format(verb_word))
return
if len(command) >= 2:
noun_word = command[1]
print(verb(noun_word))
else:
print(verb("Nothing. Nada"))
def say(noun):
return "You said {}".format(noun)
verb_dict = {"say": say,
"examine": examine,
"hit": hit,
# "stab": stab,
# "stroke": stroke
}
while True:
get_input()
Related
The part with the goblin works but the part with the elf doesn't.
#importing the random module
import random
#creating the game object class
class GameObject:
class_name = ""
desc = ""
objects = {}
def __init__(self, name):
self.name = name
GameObject.objects[self.class_name] = self
#defining the description
def get_desc(self):
return self.class_name + "\n" + self.desc
#creating the goblin class
class Goblin(GameObject):
def __init__(self, name):
self.class_name = "goblin"
self.health = 3
self._desc = "A foul creature"
super().__init__(name)
#property
def desc(self):
if self.health >= 3:
return self._desc
elif self.health == 2:
x = random.randint(13, 35)
health_line = "You struck and dealt " + str(x) + " damage!"
elif self.health == 1:
y = 40 - random.randint(13, 35)
health_line = "You rushed and dealt " +str(y) + " damage! \n Goblin activated effect Rage!"
elif self.health <= 0:
health_line = "It is dead."
return self._desc + "\n" + health_line
#desc.setter
def desc(self, value):
self._desc = value
#creating the goblin object
goblin = Goblin("Gobbly")
#creating the elf class
class Elf(GameObject):
def __init__(self, name):
self.class_name = "Elf"
self.health = 5
self._desc = "A strong warlock"
super().__init__(name)
#property
def desc(self):
if self.health >= 5:
return self._desc
elif self.health == 4:
x = random.randint(20, 50)
health_line = " You struck and dealt " + str(x) + " damage!"
elif self.health == 3:
x = random.randint(20, 40)
health_line = " You countered and dealt " + str(x) + " damage!"
elif self.health == 2:
y = 40 - random.randint(20, 50)
health_line = "You rushed and dealt " +str(y) + " damage! \n Elf activated effect Sectum Sempra!!"
elif self.health == 1:
y = 40 - random.randint(20, 50)
health_line = " You struck and dealt " + str(x) + " damage!"
elif self.health <= 0:
health_line = "It is dead."
return self._desc + "\n" + health_line
#desc.setter
def desc(self, value):
self._desc = value
#creating an elf object
elf = Elf("Elfy")
#defining the hit verb
def hit(noun):
if noun in GameObject.objects:
thing = GameObject.objects[noun]
if type(thing) == Goblin:
thing.health -= 1
if thing.health <= 0:
msg = "You killed the goblin!"
else:
msg = "You hit the {}".format(thing.class_name)
elif type(thing) == Elf:
thing.health -= 1
if thing.health <= 0:
msg = "You killed the elf!"
else:
msg = "You hit the {}".format(thing.class_name)
else:
msg = "There is no {} here.".format(noun)
return msg
#defining the examine verb
def examine(noun):
if noun in GameObject.objects:
return GameObject.objects[noun].get_desc()
else:
return "There is no {} here.".format(noun)
#getting input
def get_input():
command = input(": ").split()
verb_word = command[0]
if verb_word in verb_dict:
verb = verb_dict[verb_word]
else:
print("Unknown verb {}".format(verb_word))
return
if len(command) >= 2:
noun_word = command[1]
print(verb(noun_word))
else:
print(verb("nothing"))
#defining the say verb
def say(noun):
return 'You said "{}"'.format(noun)
#the verbs
verb_dict = {
"say": say,
"examine": examine,
"hit": hit
}
while True:
get_input()
It's supposed to say |you hit the elf| when I type |hit elf| like how it says |you hit the goblin| when I type |hit goblin|
I just started learning oop in python and some parts are confusing. If anyone understands, please help me fix the code.
At first elif refers to else if , that simply means that if statement is activated then the elif statement gets skipped . So try replacing elif with if . If problem still continues , reply.
I don't see that you need to check the type of the object here:
def hit(noun):
if noun in GameObject.objects:
thing = GameObject.objects[noun]
thing.health -= 1
if thing.health <= 0:
msg = "You killed the {}!".format(thing.class_name.lower())
else:
msg = "You hit the {}".format(thing.class_name)
else:
msg = "There is no {} here.".format(noun)
return msg
I have been trying to get my objects to be printed out as list. The list is the inventory. It should be printed out by typing i. But I only an error that shows there objects in a list that can't be printed. I keep getting an error. Please can you help me?
def play():
while True:
Action_input = get_player_action()
if Action_input in ["n","North"]:
print("Go North")
elif Action_input in ["s","South"]:
print("Go South")
elif Action_input in ["e","East"]:
print("Go East")
elif Action_input in ["w","West"]:
print("Go West")
elif Action_input in ["i","I"]:
print("Inventory")
for i in inventory:
print(inventory)
else:
print("Not an availble direction. Use only n,e,w,s,North,South,East, or West")
class Resources:
def __init__(self):
self.name = name
self.description = description
self.health = health
def __str__(self):
return " Name: " + self.name + "Description: " + str(self.description) + " Damage: " + str(self.damage)
class bread(Resources):
def __init__(self):
self.name = "bread"
self.description = "A kind of food that is cheap and nice."
self.health = 4
class pako(Resources):
def __init__(self):
self.name = "pako"
self.description = "A long piece of wood that can be used as a weapon"
self.damage = 10
class punch(Resources):
def __init__(self):
self.name = "punch"
self.description = "Using the fist to strike"
self.damage = 6
class owo(Resources):
def __init__(self):
self.name = "owo"
self.description = "What you use to buy goods or services"
self.value = 10
def get_player_action():
return input("What is your move?")
def best_attack_move(inventory):
Max_Attack = 0
Best_attack_move = None
for item in inventory:
if item.damage > Max_Attack:
Best_attack_move = item
Max_Attack = item.damage
return Best_attack_move
inventory = [bread(),pako(),punch(),owo()]
play()
Error:
What is your move?i
Inventory
[<main.bread object at 0x02ADC418>, <main.pako object at 0x02ADC448>, <main.punch object at 0x02ADC478>, <main.owo object at 0x02ADC4A8>]
[<main.bread object at 0x02ADC418>, <main.pako object at 0x02ADC448>, <main.punch object at 0x02ADC478>, <main.owo object at 0x02ADC4A8>]
[<main.bread object at 0x02ADC418>, <main.pako object at 0x02ADC448>, <main.punch object at 0x02ADC478>, <main.owo object at 0x02ADC4A8>]
[<main.bread object at 0x02ADC418>, <main.pako object at 0x02ADC448>, <main.punch object at 0x02ADC478>, <main.owo object at 0x02ADC4A8>]
What is your move?
a simple solution to your problem is in for loop.
elif Action_input in ["i","I"]:
print("Inventory")
for i in inventory:
print(i)
Replace inventory by i. also there are few errors as described below.
In bread class
class bread(Resources):
def __init__(self):
self.name = "bread"
self.description = "A kind of food that is cheap and nice."
self.health = 4
replace self.health by self.damage
and same for owo class
class owo(Resources):
def __init__(self):
self.name = "owo"
self.description = "What you use to buy goods or services"
self.damage = 10
replace self.value by above
Your final code should look alike
def play():
while True:
Action_input = get_player_action()
if Action_input in ["n","North"]:
print("Go North")
elif Action_input in ["s","South"]:
print("Go South")
elif Action_input in ["e","East"]:
print("Go East")
elif Action_input in ["w","West"]:
print("Go West")
elif Action_input in ["i","I"]:
print("Inventory")
for i in inventory:
print(i)
else:
print("Not an availble direction. Use only n,e,w,s,North,South,East, or West")
class Resources:
def __init__(self):
self.name = name
self.description = description
self.health = health
def __str__(self):
return " Name: " + self.name + "\n Description: " + str(self.description) + "\n Damage: " + str(self.damage)
class bread(Resources):
def __init__(self):
self.name = "bread"
self.description = "A kind of food that is cheap and nice."
self.damage = 4
class pako(Resources):
def __init__(self):
self.name = "pako"
self.description = "A long piece of wood that can be used as a weapon"
self.damage = 10
class punch(Resources):
def __init__(self):
self.name = "punch"
self.description = "Using the fist to strike"
self.damage = 6
class owo(Resources):
def __init__(self):
self.name = "owo"
self.description = "What you use to buy goods or services"
self.damage = 10
def get_player_action():
return input("What is your move?")
def best_attack_move(inventory):
Max_Attack = 0
Best_attack_move = None
for item in inventory:
if item.damage > Max_Attack:
Best_attack_move = item
Max_Attack = item.damage
return Best_attack_move
inventory = [bread(),pako(),punch(),owo()]
play()
You need to put every instance of the inventory variable inside str(), and also.
inventory = [str(bread()),str(pako()),str(punch()),str(owo())]
(By the way, the bread and owo have no damage attribute, so you will get an error about it)
I have the following code:
import options
import random
class Player():
def __init__(self):
self.name = None
self.gold = 100
self.maxhealth = 100
self.health = self.maxhealth
self.level = 1
self.exp = 0
self.levelUp = 50
self.gainedexp = self.levelUp - self.exp
def get_name(self):
self.name = input("Hey there, traveller! What's your name?\n~~>")
print("Since you are new around here, 100 gold doubloons have been given to you, {}!".format(self.name))
def gold_counter(self):
print("You currently have {} gold!".format(player.gold))
class Dragon():
def __init__(self):
self.name = "Dragon"
self.dropgold = random.randint(13,20)
self.minexp = int(15 * round(player.level * 1.5))
self.maxexp = int(30 * round(player.level * 1.5))
self.expgain = random.randint({}, {}.format(self.minexp, self.maxexp))
self.maxhealth = 80
self.health = self.maxhealth
def intro():
wrong_input = 0
nar_name = "Narrator"
print("{}: Uhhhm...".format(nar_name))
print("{}: Let me check my list...".format(nar_name))
print("{0}: Ah! Yes! {1}, that's right. I heard you were supposed to be arriving today.".format(nar_name, player.name))
I am also using two other modules, but I'm 99% sure they don't affect this. I get the following output:
Hey there, traveller! What's your name?
~~>Savage Potato
Since you are new around here, 100 gold doubloons have been given to you, Savage Potato!
Do you want to see your balance?
~~> Yes
You currently have 100 gold.
Narrator: Uhhhm...
Narrator: Let me check my list...
Narrator: Ah! Yes! None, that's right. I heard you were supposed to be arriving today.
In the last line, it is printing out the Narrator's name, but not the user's inputted name. I also looked at the python documents on their website, but I couldn't find a fix. Any ideas on how I could stop it from outputting None as the user's name?
EDIT #1: I have player = Player() written later in the module.
EDIT #2: This is all the code I used:
Module 1 (main.py)
import prints
import random
class Player():
def __init__(self):
self.name = None
self.gold = 100
self.maxhealth = 100
self.health = self.maxhealth
self.level = 1
self.exp = 0
self.levelUp = 50
self.gainedexp = self.levelUp - self.exp
def get_name(self):
self.name = input("Hey there, traveller! What's your name?\n~~>")
print("Since you are new around here, 100 gold doubloons have been given to you, {}!".format(self.name))
class Dragon():
def __init__(self):
self.name = "Dragon"
self.dropgold = random.randint(13,20)
self.minexp = int(15 * round(player.level * 1.5))
self.maxexp = int(30 * round(player.level * 1.5))
self.expgain = random.randint({}, {}.format(self.minexp, self.maxexp))
self.maxhealth = 80
self.health = self.maxhealth
#while player.exp >= player.levelUp:
#player.levelUp += 1
#player.exp = player.exp - player.levelUp
#player.levelUp = round(player.levelUp * 1.5)
#print("Congrats! You just levelled up to level {} by gaining {} experience!".format(player.level, player.gainedexp))
def start():
player.get_name()
prints.gold_counter()
prints.intro()
prints.encounter()
player = Player()
start()
Module 2 (prints.py)
import options
import random
class Player():
def __init__(self):
self.name = None
self.gold = 100
self.maxhealth = 100
self.health = self.maxhealth
self.level = 1
self.exp = 0
self.levelUp = 50
self.gainedexp = self.levelUp - self.exp
def get_name(self):
self.name = input("Hey there, traveller! What's your name?\n~~>")
print("Since you are new around here, 100 gold doubloons have been given to you, {}!".format(self.name))
def gold_counter(self):
print("You currently have {} gold!".format(player.gold))
class Dragon():
def __init__(self):
self.name = "Dragon"
self.dropgold = random.randint(13,20)
self.minexp = int(15 * round(player.level * 1.5))
self.maxexp = int(30 * round(player.level * 1.5))
self.expgain = random.randint({}, {}.format(self.minexp, self.maxexp))
self.maxhealth = 80
self.health = self.maxhealth
def intro():
wrong_input = 0
nar_name = "Narrator"
print("{}: Uhhhm...".format(nar_name))
print("{}: Let me check my list...".format(nar_name))
print("{0}: Ah! Yes! {1}, that's right. I heard you were supposed to be arriving today.".format(nar_name, player.name))
print("{}: Welcome to... THE DRAGON FIGHTER GAME!".format(nar_name))
print("{}: I know, it isn't the most imaginative name.".format(nar_name))
print("{}: Don't look at me like that, I tried my hardest!".format(nar_name))
print("{}: Anyhoo, let's carry on.".format(nar_name))
print("{}: For some stupid reason, the creator of this game didn't give me an actual name, so\nmy name is just \"Narrator\" or \"N\", but you can call me Larry.".format(nar_name))
while True:
option = input("Narrator: Actually, which name would you prefer to call me?\n").upper()
if option in options.nar_larry_opt:
nar_name = "Larry"
elif option in options.nar_narrator_opt:
nar_name = "Narrator"
while True:
ask = input("{}: Maybe \"N\" for short?".format(nar_name)).upper()
if ask in options.inp_yes_opt:
nar_name = "N"
elif ask in options.inp_no_opt:
break
else:
wrong_input += 1
if wrong_input == 1:
print("Please try again.")
elif wrong_input == 2:
print("Try to not put the same thing in next time.")
elif wrong_input == 3:
print("This isn't funny.")
elif wrong_input == 4:
print("Seriously.")
elif wrong_input == 5:
print("OKAY! THIS IS IT! GO BACK TO THE BEGINNING!")
intro()
continue
break
else:
print("Please try again.")
continue
break
print("{}: So, as I was saying, this game is basically just some dragon quest thingy.".format(nar_name))
print("{}: You'll probably get tips from me every now and again if I can be bothered.".format(nar_name))
print("{}: I'll get an test encounter ready.".format(nar_name))
def gold_counter():
while True:
option = input("Do you want to see your balance?\n~~> ").upper()
if option in options.inp_yes_opt:
print("You currently have {} gold.".format(player.gold))
elif option in options.inp_no_opt:
print("You can check your balance later in the game.")
else:
print("Please try again.")
continue
break
def encounter():
while True:
dragon_appear = random.randint(1,2)
if dragon_appear == 1:
print("What's that? Looks like a huge bir... \nA DRAGON! A MAJESTIC DRAGON JUST FLEW DOWN FROM THE SKY!")
else:
print("What's that? Looks like a huge bir... \n Yeah. Just a giganta-bird.")
while encounter().dragon_appear != 2:
print("So that's the message you'll get when a dragon appears.")
print("And you will be prompted whether you want to run or fight, like so:")
while True:
wrong_input = 0
ask = input("Run away like a coward, or fight the majestic beast?")
if ask in options.enc_run_opt:
escape = random.randint(1,2)
if escape == 1:
print("You managed to get away!")
else:
print("You didn't get away. Better luck next time!")
elif ask in options.enc_attack_opt:
pass
else:
wrong_input += 1
if wrong_input == 1:
print("Please try again.")
elif wrong_input == 2:
print("Try to not put the same thing in next time.")
elif wrong_input == 3:
print("This isn't funny.")
elif wrong_input == 4:
print("Seriously.")
continue
break
player = Player()
Module 3 (options.py)
inp_yes_opt = {"Y", "YE", "YES", "YEAH", "PLEASE", "YES PLEASE"}
inp_no_opt = {"N", "NO", "NOPE", "NAH"}
nar_larry_opt = {"LARRY", "LARR", "LAR", "LA", "L", "LARRY PLEASE"}
nar_narrator_opt = {"NARRATOR", "NARR", "N", "NAR", "NARRATE", "NOT LARRY"}
enc_run_opt = {"RUN", "RU", "R", "SCRAM", "RUN AWAY", "RUUUUN"}
enc_attack_opt = {"ATTACK", "ATTAK", "A", "FIGHT", "F", "ATTACK", ""}
If you want to print out the name of the player , you need to pass in the player object to the intro function as a parameter. That assumes intro is not capturing the player object and the player object is not global
At the moment , it seems there is no player object accessible to the scope of the function which is why it outputs None
I'm relatively new to python and I've been trying to practice OOP in python with this example:
def get_input():
command = input(':').split()
verb_word = command[0]
if verb_word in verb_dict:
verb = verb_dict[verb_word]
else:
print('Unkown verb "{}"'.format(verb_word))
return
if len(command) >= 2:
noun_word = command[1]
print(verb(noun_word))
else :
print(verb('nothing'))
def say(noun):
return "You said '{}'".format(noun)
class GameObject:
class_name = ""
_desc = ""
health_line = ""
objects = {}
def __init__(self,name):
self.name = name
GameObject.objects[self.class_name] = self
def desc(self):
return self.class_name + "\n" + self._desc + "\n" + self.health_line
class Goblin(GameObject):
def __init__(self,name):
self.class_name = "goblin"
self.health = 3
self._desc = 'A foul creature'
super().__init__(name)
#property
def desc(self):
if self.health >= 3:
return self._desc
elif self.health == 2:
health_line = 'It is badly bruised'
elif self.health == 1:
health_line = 'It is barely standing'
elif self.health <= 0:
health_line = 'It is dead'
return self._desc +'\n'+ self.health_line
#desc.setter
def desce(self,value):
self.__desc = value
goblin = Goblin("Gobbly")
def hit(noun):
if noun in GameObject.objects:
thing = GameObject.objects[noun]
if type(thing) == Goblin:
thing.health = thing.health - 1
if thing.health <= 0:
msg = "You killed it"
else:
msg = "You hit the {}".format(thing.class_name)
else:
msg = "There is no {} here".format(noun)
return msg
def examine(noun):
if noun in GameObject.objects:
return GameObject.objects[noun].desc()
else:
return "There is no '{}' here".format(noun)
verb_dict ={"say":say,"examine":examine,"hit":hit}
while True :
get_input()
It seems that this line:
return GameObject.objects[noun].des()
returns the Type Error. I'm not sure why this is, and I've been at this for a while. Any help is much appreciated.
If you want to call the desc function, you will have to do it as such:
GameObject.desc(parameter)
where the parameter can be object[noun]. This is because the desc method belongs to the GameObject class.
I'm a beginner and stumbled across an issue with inheritance.
When I use this block of code, the program doesn't work correctly thanks to a line in the enter function:
class Bathroom(Room):
def __init__(self):
super(Bathroom, self).__init__("bathroom")
def enter(self, world, player):
super(Bathroom, self).enter(world, player)
But, when I use this, it does:
class Bathroom(Room):
def __init__(self):
super(Bathroom, self).__init__("bathroom")
Are they not the same thing?
The full script I've written (not finished btw) is below. When I enter 'y' after being asked 'Do you want to leave', the program finishes when I use 'super' to inherit the enter function. If I don't, the program works:
while player and self.name != "corridor":
response = self._ask_question("Do you want to leave? (y/n) ", "y", "n")
if response == "y":
return world.corridor
elif response == "n" and self.enemy:
print("The", self.enemy, "kills you. You didn't even put up a\
fight")
return world.death
Full script:
import random
import time
# bad from sys import exit
class Character(object):
def __init__(self, name, health, attack):
self.name = name
self.health = health
self.attack = attack
def __str__(self):
return str(self.health) + " health and " + str(self.attack) + " attack."
class Room(object):
def __init__(self, name):
self.name = name
self.enemy = self._getRandEnemy()
def enter(self, world, player):
print(player.name + ",", "you are in the", self.name + ". You have\
" + str(player))
if self.enemy: # you may have killed it
print("But, wait! There's a", self.enemy.name, "with " + str(\
self.enemy))
response = self._ask_question("Do you stay and fight?(y/n)\
", "n", "y")
if response == "n":
pass
if response == "y":
self.combat(player, self.enemy)
else:
print("No enemies here.")
# check if player has no health after potential fight
if player.health < 1:
return world.death
while player and self.name != "corridor":
response = self._ask_question("Do you want to leave? (y/n) ", "y", "n")
if response == "y":
return world.corridor
elif response == "n" and self.enemy:
print("The", self.enemy, "kills you. You didn't even put up a\
fight")
return world.death
def _getRandEnemy(self):
names = ["Troll", "Witch", "Ogre", "Jeremy Corbyn"]
return Character(random.choice(names), random.randint(4, 6),\
random.randint(2, 3))
def _ask_question(self, question, a, b):
response = None
while response not in(a, b):
response = input(question)
return response
def combat(self, player, enemy):
while player.health > 0 and enemy.health > 0:
time.sleep(1)
print("You attack and deal", player.attack, "damage")
enemy.health -= player.attack
if enemy.health >= 1:
print("The enemy has " + str(self.enemy))
time.sleep(1)
print("The", self.enemy.name, "attacks and deals you",\
self.enemy.attack, "\
damage.")
player.health -= enemy.attack
print("You have " + str(player))
if player.health < 1:
pass
if enemy.health < 1:
print("Ha! Got him!")
self.enemy = None
class Corridor(Room):
def __init__(self):
self.name = "corridor"
self.enemy = None
def enter(self, world, player):
super(Corridor, self).enter(world, player)
room = self._ask_question("Which room: bathroom, bedroom ",\
"bedroom", "bathroom", "Library", "study")
if room == "bedroom":
return world.bedroom
if room == "bathroom":
return world.bathroom
class Bathroom(Room):
def __init__(self):
super(Bathroom, self).__init__("bathroom")
def enter(self, world, player):
super(Bathroom, self).enter(world, player)
class Bedroom(Room):
def __init__(self):
super(Bedroom, self).__init__("bedroom")
class Death(Room):
def __init__(self):
super(Death, self).__init__("death")
def enter(self, world, player):
time.sleep(1)
responses = ["Off to the man in sky. You are dead", "You died,\
no-one cried.", "Lolz. You're dead!"]
print(random.choice(responses))
return None
class World(object):
def __init__(self):
self.corridor = Corridor()
self.bathroom = Bathroom()
self.death = Death()
self.bedroom = Bedroom()
self.start = self.corridor
def play_game(world, player):
room = world.start
while room:
room = room.enter(world, player)
play_game(World(), Character("Bob", 12, 2))
I know I must be missing something obvious.
Thanks, Dave.
You forgot to return the result of the super().enter() call. You are swallowing the return value, so you never returned the new room. The following would be correct:
class Bathroom(Room):
def enter(self, world, player):
return super(Bathroom, self).enter(world, player)
Not that there is a point in defining a new Bathroom().enter() method if all you do is call the original version with super(). You may as well remove the whole enter() method (as I've done for the __init__ method, above).