logo

Crowdly

In this exercise, we have a python script of Langton's ant that uses a 50 by 50 ...

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

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 meant to load a predefined grid.

The only missing thing is the coding of the "load" button. We want this button to read an existing text file named "grid_save.txt"containing the state of the grid as text.

For example, if the text file contains:

0101

1101

0010

1110

We want the grid to be updated as:

[[0, 1, 0, 1],

 [1, 1, 0, 1],

 [0, 0, 1, 0],

 [1, 1, 1, 0]]

Here is the part of the code where the loading of the grid should be implemented:

new_file = open("grid_save.txt", "r")

if load == True:

x = 0

y = 0

for line in new_file:

line = line.strip(???)

y = y + 1

for character in line:

grid[y][x] = ???

x = x + 1

new_file.close()

Write the 2 missing pieces of code represented by ???. Seperate both line with a semi-colon ";".

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на moodle.ecam.fr?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!