May I please know how to program this question in python? Than you. You are task
ID: 3719120 • Letter: M
Question
May I please know how to program this question in python? Than you.
You are tasked with writing a program that will calculate the cost of moving fronm one block to another. You will be given a width (N) and Height (M) integer that specifies the size of the map. You will also be provided with X1, Y2 and X2, Y2 coordinates for source and destination coordinates The arguments to your program are: N - Width as integer M - Height as integer C-Cost per a block as float · X1-X Starting Position as integer Y1-Y Starting Position as integer . X2-X End Position as integer Y2-Y End Position as integer If the number of arguments specified does not match what is required your program will need to exit immediately. The total cost is determined by the amount of blocks travelled (Blocks Edit: Updated traveled to travelled Example 1: python manhattan.py 43 10.00 00 11 This trip will cost $20.00 and you will have travelled 2 blocks C)Explanation / Answer
import sys
def find_Dist(x1,y1,x2,y2):
return abs(x1-x2)+abs(y1-y2)#manhattan distance formula
def find_cost(dist,cost):
return dist*cost
inp_arg = sys.argv
print inp_arg
n = int(inp_arg[1])
m = int(inp_arg[2])
c = float(inp_arg[3])
x1 = int(inp_arg[4])
y1 = int(inp_arg[5])
x2 = int(inp_arg[6])
y2 = int(inp_arg[7])
if(x1<0 or x1>n or x2<0 or x2>m):
print "Invalid input input must be in range"
else:
dist = find_Dist(x1,y1,x2,y2)
cost = find_cost(dist,c)
print "The trip will cost $"+str(cost),"and youwill have travelled",dist,"blocks"