python code pdf
python code pdf
graph = {
'A': ['B', 'C','D'],
'B': ['F', 'E'],
'C': ['G'],
'D': ['H','I'],
'E': ['J'],
'F': ['K'],
'G': [],
'H': ['L'],
'I': ['M'],
'J': ['N'],
'K': [],
'L': [],
'M': [],
'N': []
}
visited = []
queue = []
while queue:
s = queue.pop(0)
print(s, end=" ")
# Driver Code
bfs(visited, graph, 'A')
print('\n')
print(visited)
def sense(self):
return self.environment[self.location]
def simulate_environment():
return {"A": random.randint(0, 1), "B":
random.randint(0, 1)}
def main():
environment = simulate_environment()
agent = VacuumCleanerAgent(environment)
if dirt_status == 1:
print("Agent cleaning...")
agent.act("clean")
else:
action = random.choice(["left", "right"])
print(f"Agent moving {action}...")
agent.act(action)
print("---------")
if __name__ == "__main__":
main()
self.image = wx.StaticBitmap(self.panel,
wx.ID_ANY, wx.NullBitmap, size=(400, 300))
self.load_button = wx.Button(self.panel,
label="Load Image")
self.load_button.Bind(wx.EVT_BUTTON,
self.load_image)
self.remove_bg_button = wx.Button(self.panel,
label="Remove Background")
self.remove_bg_button.Bind(wx.EVT_BUTTON,
self.remove_background)
self.file_picker =
filebrowse.FileBrowseButton(self.panel, labelText="Image
File", fileMask="*.png;*.jpg;*.jpeg;*.bmp;*.gif")
self.save_button = wx.Button(self.panel,
label="Save Image")
self.save_button.Bind(wx.EVT_BUTTON,
self.save_image)
self.panel.SetSizer(self.sizer)
self.Layout()
self.modified_image = None
if dialog.ShowModal() == wx.ID_OK:
filepath = dialog.GetPath()
dialog.Destroy()
self.file_picker.SetValue(filepath)
self.display_image(filepath)
self.image.SetBitmap(bitmap)
self.modified_image = None # Reset modified
image when loading a new one
if filepath:
with open(filepath, "rb") as input_file:
input_data = input_file.read()
output_data = rembg.remove(input_data)
output_image =
wx.Image(io.BytesIO(output_data), wx.BITMAP_TYPE_ANY)
output_image = output_image.Scale(400, 300,
wx.IMAGE_QUALITY_HIGH)
self.modified_image =
output_image.ConvertToBitmap()
self.image.SetBitmap(self.modified_image)
if dialog.ShowModal() == wx.ID_OK:
filepath = dialog.GetPath()
dialog.Destroy()
self.modified_image.SaveFile(filepath,
wx.BITMAP_TYPE_PNG)
class GradientPanel(wx.Panel):
def __init__(self, parent):
super(GradientPanel, self).__init__(parent)
self.Bind(wx.EVT_PAINT, self.on_paint)
def main():
app = wx.App(False)
frame = RemoveBackgroundApp(None, "Remove Background
App")
frame.Show()
app.MainLoop()
if __name__ == "__main__":
main()