Question: So I was told to make a treasure map using simple 5 treasures in python using turtle. I created five different treasure as below and

So I was told to make a treasure map using simple 5 treasures in python using turtle. I created five different treasure as below and displayed them on the right-hand side of the treasure map as a legend. Using the code below, however it asked me to make the shaped or treasure to follow a certain path. How can i make them follow a random path? Everything i had did is under def follow_path and def random_path is a code given:

import turtle

def random_path(print_path = True): # Select one of the five starting points, with a random token path = [['Start', choice(starting_points), randint(0, 4)]] # Determine our location in grid coords (assuming num_squares is odd) start_coords = {'Top left': [0, num_squares - 1], 'Bottom left': [0, 0], 'Top right': [num_squares - 1, num_squares - 1], 'Centre': [num_squares // 2, num_squares // 2], 'Bottom right': [num_squares - 1, 0]} location = start_coords[path[0][1]] # Keep track of squares visited been_there = [location] # Create a path up to 19 steps long (so at most there will be 20 tokens) for step in range(randint(0, 19)): # Find places to go in each possible direction, calculating both # the new grid square and the instruction required to take # us there go_north = [[[location[0], new_square], ['North', new_square - location[1], token]] for new_square in range(location[1] + 1, num_squares) for token in [0, 1, 2, 3, 4] if not ([location[0], new_square] in been_there)] go_south = [[[location[0], new_square], ['South', location[1] - new_square, token]] for new_square in range(0, location[1]) for token in [0, 1, 2, 3, 4] if not ([location[0], new_square] in been_there)] go_west = [[[new_square, location[1]], ['West', location[0] - new_square, token]] for new_square in range(0, location[0]) for token in [0, 1, 2, 3, 4] if not ([new_square, location[1]] in been_there)] go_east = [[[new_square, location[1]], ['East', new_square - location[0], token]] for new_square in range(location[0] + 1, num_squares) for token in [0, 1, 2, 3, 4] if not ([new_square, location[1]] in been_there)] # Choose a free square to go to, if any exist options = go_north + go_south + go_east + go_west if options == []: # nowhere left to go, so stop! break target_coord, instruction = choice(options) # Remember being there been_there.append(target_coord) location = target_coord # Add the move to the list of instructions path.append(instruction) # To assist with debugging and marking, print the list of # instructions to be followed to the shell window print('Welcome to the Treasure Hunt!') print('Here are the steps you must follow...') for instruction in path: print(instruction) # Return the random path return path

def follow_path(random_path):

def Square(): pendown(); forward(100) left(90) forward(100) left(90) forward(100) left(90) forward(100) penup()

def Circle(): pendown(); circle(50); penup(); def Rectangle(): pendown(); forward(100) left(90) forward(50) left(90) forward(100) left(90) forward(50) penup(); def Traingle(): pendown(); forward(100) left(120) forward(100) left(120) forward(100) penup(); def Pentagon(): pendown(); forward(100) left(60) forward(100) left(60) forward(100) left(60) forward(100) left(60) forward(100) left(60) forward(100) penup(); def drawlegend(): tokens = [Square,Circle,Rectangle,Traingle,Pentagon]; penup(); setposition(750,50); tokens[0](); setposition(860,80); color('black') write("Square", align="left", font=("Times", 36, "bold")) setposition(750,160); tokens[1](); setposition(860,190); color('black') write("Circle", align="left", font=("Times", 36, "bold")) setposition(750,270); tokens[2](); setposition(860,300); color('black') write("Rectangle", align="left", font=("Times", 36, "bold")) setposition(750,380); tokens[3](); setposition(860,410); color('black') write("Triangle", align="left", font=("Times", 36, "bold")) setposition(750,490); tokens[4](); setposition(860,520); color('black') write("Pentagon", align="left", font=("Times", 36, "bold")) pendown() myTurtle.color("black") drawlegend();

(treasure map design has been given with a code and treasure map looks like this 7x7, the legend is placed on the right side outside the treasure map(table))

each block of the treasure map is 100X100 pixels big which was used to make the shapes(treasures)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!