Write a program that allows the user to input the r- and y-coordinates of two squares, and then prints out whether or not they form a valid ship – meaning that both squares lie on the grid, and are adjacent to one another horizontally or vertically. If one of those conditions is not met, the program should print out a message saying which condition is wrong. (If both conditions are not met, the program only needs to output a single message, which can be either one, your choice.) For example, here is a sample run: Enter x-coordinate of square one: 3 Enter y-coordinate of square one: 2 Enter x-coordinate of square two: 3 Enter y-coordinate of square two: 3 Valid - here, the numbers are input by the user, and everything else is produced by the program; this is Valid because it corresponds to the first placement shown in the figure above. Other sample runs might look like: Enter x-coordinate of square one: 3 Enter y-coordinate of square one: -1 Enter x-coordinate of square two: 5 Enter y-coordinate of square two: 2 Square(s) not on grid
Write a program that allows the user to input the r- and y-coordinates of two squares, and then prints out whether or not they form a valid ship – meaning that both squares lie on the grid, and are adjacent to one another horizontally or vertically. If one of those conditions is not met, the program should print out a message saying which condition is wrong. (If both conditions are not met, the program only needs to output a single message, which can be either one, your choice.) For example, here is a sample run: Enter x-coordinate of square one: 3 Enter y-coordinate of square one: 2 Enter x-coordinate of square two: 3 Enter y-coordinate of square two: 3 Valid - here, the numbers are input by the user, and everything else is produced by the program; this is Valid because it corresponds to the first placement shown in the figure above. Other sample runs might look like: Enter x-coordinate of square one: 3 Enter y-coordinate of square one: -1 Enter x-coordinate of square two: 5 Enter y-coordinate of square two: 2 Square(s) not on grid
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 2GZ
Related questions
Question
Simple python
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,