I am trying to create 10 instances of my class Rooms
by taking user input which contains a number
, a dictionary
and a string value , this is my code :
class Rooms:
def __init__(self, number, items, hotelname):
self.number = number
self.items = items
self.hotelname = hotelname
@classmethod
def from_input(cls):
return cls(
input('ID of Rooms: '),
dict(input('enter commodities with price \n').split() for _ in range(5)),
str(input('name of hotel ')),
)
def main():
rooms = {}
for _ in range(10): # create 10 rooms
room = Rooms.from_input() # from room input
rooms[room.items] = room # and store them in the dictionary
if __name__=="__main__":
main()
I'm getting the error in linerooms[room.items] = room # and store them in the dictionary
as
TypeError: unhashable type: 'dict'
.
I'm a noob in programming. I searched a lot of posts but didn't understand what I'm doing wrong. Can this not be done?
My final goal is to Print out each room along with the individual items and values.