Question

In: Computer Science

python codes question i need python codes to make robot tranverses the maze from its current...

python codes question
i need python codes to make robot tranverses the maze from its current locations then returns to its current position. Then the robot marks the location with special token and the ones he has revisited with another special token.

Solutions

Expert Solution

#!/usr/bin/env python3

class Robot:

def_init_(self,instruction_file):

self.instruction_list=None

def write_instructions(self):

f=open(self.instruction_file,'w')

while True:

movement_x=input("enter horizontal movement,or q to quit:")

if movement_x== 'q':

break

movement_y=input('enter vertical movement, or q to quit:' )

if movement_y=='q':

break#store x and y movements alternately on separate lines

#write both x and y movements when both are received

f.write(movement_x+'\n')

f.write(movement_y+'\n')

f.close()

def read_instruction(self):

try:

f=open(self.instruction_file,'r')

print (error)

else:

#store (movements +'\n')as elements in alist

self.instructions_list+f.readlines()

f.close()

def get_location(self):

position_x,position_y=0,0

distance_x,distance_y=0,0

self.read_instructions()

if self.instructions_list !=None:

for data in self.instruction_list:

# exclude'\n' at the end of the movement

temp=data[:-1]

#get x movement from odd line numbers

if self.instructions_list.index(data)%2==0:

position_x +=float (temp)

distance_x +=abs(float temp))

else:

get y movement from even line numbers

position_y +=float (temp)

distance_y +=abs(float temp))

return position_x,position_y, distance_x,distance_y

Robot_1=Robot('robot _1.get_location()

print(' the robot is finally at ' +str(pos_x))

print('the robot has traveled a distance of ' +str(dis_x) +'horizontally, ')

+str(dis_y)+ 'vertically')


Related Solutions

i need a design for a robot to be placed in swimming pools that detects drowning...
i need a design for a robot to be placed in swimming pools that detects drowning , in case drowning is detected it will automatically inflate an airbag to rescue the swimmer
i need a design for a robot to be placed in swimming pools that detects drowning...
i need a design for a robot to be placed in swimming pools that detects drowning , in case drowning is detected it will automatically inflate an airbag to rescue the swimmer NOTE we need a design without using cameras and image processing the robot will be in the swimming pool
I need the matlab codes for following question (1) (a). Solve the following second-order differential equations...
I need the matlab codes for following question (1) (a). Solve the following second-order differential equations by a pair of first-order equations, xyʹʹ − yʹ − 8x3y3 = 0; with initial conditions y = 0.5 and yʹ = −0.5 at x = 1. (b). Solve the problem in part (a) above using MATLAB built-in functions ode23 and ode45, within the range of 1 to 4, and compare with the exact solution of y = 1/(1 + x2) [Hint: ode23 à...
I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
I just need to understand Question 1 and 2. I just wanted to make sure I...
I just need to understand Question 1 and 2. I just wanted to make sure I did the revenue management right. Freedom Airlines recently started operations in the Southwest. The airline owns two airplanes, one based in Phoenix and the other in Denver. Each airplane has a coach section with 140 seats available. Each afternoon, the Phoenix based airplane flies to San Francisco with stopovers in Las Vegas and in San Diego. The Denver-based airplane also flies to San Francisco...
I just need to understand Question 1 and 2. I just wanted to make sure I...
I just need to understand Question 1 and 2. I just wanted to make sure I did the revenue management right. Freedom Airlines recently started operations in the Southwest. The airline owns two airplanes, one based in Phoenix and the other in Denver. Each airplane has a coach section with 140 seats available. Each afternoon, the Phoenix based airplane flies to San Francisco with stopovers in Las Vegas and in San Diego. The Denver-based airplane also flies to San Francisco...
I need a short and clear opinion so I can understand the question and make my...
I need a short and clear opinion so I can understand the question and make my own opinion Writing in the 19th century, the British economist Thomas Malthus argued that the law of diminishing marginal returns implied eventual misery for humanity because, in the case of agriculture, there is a fixed amount of available land and additional labor would only yield ever smaller increases in food production. The inevitable result, as Malthus saw it, was that population growth would eventually...
I need to formulate a clinical question using PICO format from my current clinical area. My...
I need to formulate a clinical question using PICO format from my current clinical area. My keywords: falls, dementia, psychotropic drugs
I need to formulate a clinical question using PICO format from my current clinical area. My...
I need to formulate a clinical question using PICO format from my current clinical area. My keywords: falls, dementia, psychotropic drugs
Leave code as is ALL I NEED IS TO MAKE THE LIST INTO ASCENDING ORDER FROM...
Leave code as is ALL I NEED IS TO MAKE THE LIST INTO ASCENDING ORDER FROM A TO Z OF ARTISTS NAMES YOU CAN USE THIS AS REFERENCE SPOTIFY LIST TOP 50 AS REFERENCE FOR CSV FILE https://spotifycharts.com/viral/ import java.io.*; public class Spotify { public static void main(String[]args) { // Read csv Spotify file located on my desktop // Download csv file, save on desktop, and add file location in csvFile = " " String csvFile = "CSVFILE LOCATION OF...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT