D. Compass Coordinates: Write a program called compass_coord.py#Given a point with integer coordinates (x, y) and a compass direction N, E, S, W, print the neighboringlattice point in the given direction. A lattice is a structure in which all points are equidistant away fromone another, in this case, each is point is 1 unit away in either the x or y direction. Print the new pointin the format (x, y).

Question
Asked Sep 4, 2019

Please help me solve this problem 

D. Compass Coordinates: Write a program called compass_coord.py
#Given a point with integer coordinates (x, y) and a compass direction N, E, S, W, print the neighboring
lattice point in the given direction. A lattice is a structure in which all points are equidistant away from
one another, in this case, each is point is 1 unit away in either the x or y direction. Print the new point
in the format (x, y).
help_outline

Image Transcriptionclose

D. Compass Coordinates: Write a program called compass_coord.py #Given a point with integer coordinates (x, y) and a compass direction N, E, S, W, print the neighboring lattice point in the given direction. A lattice is a structure in which all points are equidistant away from one another, in this case, each is point is 1 unit away in either the x or y direction. Print the new point in the format (x, y).

fullscreen
check_circleExpert Solution
Step 1

Program Instructions:

  • Create a function with two parameters a point with integer coordinates and a compass direction.
  • Add +1 or subtract -1 from points when the direction is either N, E or S, W respectively.
  • Call the functions with print to print the new point in (x, y) format.
Step 2

Program (compass_cord.py):

def find_neigh_lattice_pt(pt,direct):

  # storing the points in x and y

  x,y = pt

  # add +1 when direction is N or E

  if direct=="N" or direct == "E":

    new_point = (x+1,y+1)

  # else -1

  else:

    new_point = (x-1,y-1)

  # return the p...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour*

See Solution
*Response times may vary by subject and question
Tagged in

Engineering

Computer Science

Python

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: 1.6 Compute the scalar cardinality and the fuzzy cardinality for each of thefollowing fuzzy set.

A: The scalar cardinality of a fuzzy set is calculated using the formula:

question_answer

Q: Function #2: largest Parameters: num1 - a floating point number being compared against num2 and num3...

A: Solution:largest() function:#Define the functiondef largest(num1, num2, num3):    #Check if "num1" i...

question_answer

Q: Develop pseudocode for the problem of reading in the radius of a circle (r), calculate the area of t...

A: The program will have the following steps:Receive the input as a parameter passed to the function wh...

question_answer

Q: health informatics

A:  I think the student wants to know what health informatics is, so we will be providing a brief intro...

question_answer

Q: Find a regular grammar that generates the language L (aa∗ (ab + a)∗).

A: Solution: Given input,L(aa*(ab+a)*)Determine the regular grammar for L(aa*(ab+a)*):

question_answer

Q: Consider the following procedure: procedure mystery (x, y, z); integer x, y, z;beginz =2; y = z + x;...

A: Call by reference The arguments passed to a function will copy the address of an argument into the f...

question_answer

Q: I was asked to add the three types of comments to this class, each consisting of the same statement ...

A: Java documentation comment: This comment is used to create documentation API. The syntax for this co...

question_answer

Q: Hello,  I am trying to write a program in Pynthon. I do not know may be it is too much. Just need so...

A:  Program plan:Define a function named “main()”.Assign a file name or file path.Create an empty dicti...

question_answer

Q: What is a solid state disk?

A: Solid state disk drive or solid state drive (SSD) is a non-volatile that stores (or persists) data i...