class Hotel: def __init__(self,room,catagory): if not type(room) is int: raise TypeError() self.room = room self.catagory = catagory self.catagories = {"A":"Elite","B":"Economy","C":"Regular"} self.rooms = ["0","1","2","3","4","5"] def getRoom(self): return self.room def getCatagory(self): return self.catagory return self.catagories.get(self.catagory) def __str__(self): return "%s and %s"%(self.rooms[self.room],self.catagories.get(self.catagory)) try: # room1 = Hotel('a',"A") room2 = Hotel(1,"A") print(room2) # print(room1) except Exception as e: print(str(e))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question