✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
In this exercise, we have a python script of Langton's ant that uses a 50 by 50 grid. This grid is saved in a list of lists containing a 0 for each black cell and a 1 for each white cell. This list of list is a variable called grid.
There is a button on the window used to pause the simulation and another button meant to save the current grid.
The only missing thing is the coding of the "save" button. We want this button to create a text file named "grid_save.txt" and inside we want to write the content of the grid variable.
For example, if the grid contains:[[0, 1, 0, 1], [1, 1, 0, 1], [0, 0, 1, 0], [1, 1, 1, 0]]We want the text file to contain:0101110100101110
Here is the part of the code where the saving of the grid should be implemented:
new_file = open("grid_save.txt", "w")
file_text = ""
if saved == True:
for x in range(50):
for y in range(50):
cell = grid[y][x]
???
???
new_file.write(file_text)
new_file.close()
Write the 2 missing lines of code represented by ???. Seperate both line with a semi-colon ";".
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!