114k views
5 votes
PYTHON - Please help!

I wrote a code for the polymer chain in python (it looks like the picture in attachment). The chain moves and makes 5000 steps. I need a code which will save the coordinates of the first and last point of the chain in two separate lists after every step. I.e. the chain makes a step (every point of the chain moves in some direction), then the coordinates of the first point in the chain are saved in one list and coordinates of the last point are saved in another list, then the chain makes another step and the process is repeated.
P.s. please don't write irrelevant answers like "try to get answer on stackoverflow or github"

PYTHON - Please help! I wrote a code for the polymer chain in python (it looks like-example-1

1 Answer

4 votes

Here is code that demonstrates how you can save the coordinates of the first and last points of the chain in two separate lists after every step:

first_point_coords = [ ]

last_point_coords = [ ]

for step in range(5000):

# make the chain move here

# update the coordinates of the first and last points

first_point_coords.append((first_point_x, first_point_y))

last_point_coords.append((last_point_x, last_point_y))

This code initializes two empty lists: first_point_coords and last_point_coords. It then loops through 5000 steps, updating the coordinates of the first and last points after each step. The updated coordinates are then appended to the appropriate lists.

You may need to modify this code to fit your specific needs, such as by changing the variables first_point_x, first_point_y, last_point_x, and last_point_y to the appropriate names and values in your code.

User Irnmn
by
5.2k points