<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def create_demand(self, project_id, facility, plan, operating_system, tags=None, userdata='', hostname=None, count=1):
 """Create a new on demand device under the given project. """

        tags = {} if tags is None else tags
        hostname = self.get_random_hostname() if hostname is None else hostname
        devices = []
        for i in range(1, count + 1):
            new_hostname = hostname if count == 1 else hostname + '-' + str(i)
            self.logger.info('Adding to project %s: %s, %s, %s, %s, %r',
                             project_id,
                             new_hostname,
                             facility,
                             plan,
                             operating_system,
                             tags)
            try:
                device = self.manager.create_device(project_id=project_id,
                                                    hostname=new_hostname,
                                                    facility=facility,
                                                    plan=plan,
                                                    tags=tags,
                                                    userdata=userdata,
                                                    operating_system=operating_system)
                devices.append(device)
            except packet.baseapi.Error as msg:
                raise PacketManagerException(msg)
        return devices