In that case it is important that you do the work, so that your grade is based on your skill set and not someone else's.Quote:It is really at the expense of my grade.

15,743,429 members

We will be writing a program to determine whether two rectangles are of identical dimensions. Looking at the example above, you can see that the rectangles do indeed seem to be identical. We can check this better if we have the exact coordinates of the rectangles.

In this case we do have some data, like the position of the left side of A (Ax1) and the right side of A (Ax2). When we subtract these two, the result is one of the dimensions of A.

Ax2 - Ax1 = 7

Using Ay1 and Ay2 we can calculate the other side of that rectangle. Then we can calculate the sides of rectangle B. Are the sides equal indeed?

Provide the x coordinates of A: 0,7

Provide the y-coordinates of A: 0,4

Provide the x-coordinates of B: 6,13

Provide the y-coordinates of B: 2,6

The rectangles are identical!

Write, in a file names rechthoeken.py, a program that calculates on the basis of the provided coordinates whether the rectangles have identical dimensions. In addition, it is possible that the rectangles are also square and of identical dimensions, and in that case it must also be noted in the output. If there’s not much interesting going on with the rectangles, that fact is what is printed as a result. You may assume that the use inputs pairs of two integers. Given the example above, the user would mean that Ax1 = 0 and Ax2 = 7.

You will write a main program that asks for input and tidies it for further use. In addition there are three helper functions that you will use from the main program.

As you can see, there are two TODOs in the code. The functions are supposed to return a single value that signifies whether the check passed or not (e.g. it is square, or it isn’t). What datatype fits perfectly for returning pass/fail information?

def is_same_rectangle(ax_length: int, ay_length: int, bx_length: int, by_length: int) -> TODO: """ Checks whether the lengths of the sides are equal """

def is_square(ax_length: int, ay_length: int, bx_length: int, by_length: int) -> TODO: """ Checks whether the rectangles are (identical) squares """

def calculate_length(c1: int, c2: int) -> int: """ Calculates the length of a side from two coordinates """

if __name__ == '__main__':

Hints

You can’t perform calculations on strings, so one step of tidying your data is to convert the inputs into integers.

For the function calculate_length you don’t know in advance which coordinate is larger (think of the case: c1 = 5, c2 = 3). Ensure that the function’s output is always positive. You can write some code for this yourself or make use of a standard Python-function.

Examples

Ultimately, your program should work as demonstrated below.

Provide the x coordinates of A: 0,7 Provide the y-coordinates of A: 0,4 Provide the x-coordinates of B: 6,13 Provide the y-coordinates of B: 2,6 The rectangles are identical!

I am not sure where to start. That is why I will include the whole assignment and hopefully someone can help. I have a very urgent deadline coming up. And the teachers won't help before the deadline, only after to explain what went wrong. It is really at the expense of my grade.

In that case it is important that you do the work, so that your grade is based on your skill set and not someone else's.Quote:It is really at the expense of my grade.

Permalink

Share this answer

Comments

0x01AA
18-Sep-22 12:29pm

Not really a solution, but the truth. Therefore my 5.

Richard MacCutchan
18-Sep-22 12:30pm

Correct, but the reason for posting as a solution is to take the question out of the unanswered queue.

Member 15771187
18-Sep-22 12:36pm

I am just really having trouble with it. in the end it always seems so logical, but i need help right now.

Richard MacCutchan
18-Sep-22 12:41pm

Then you need to show the code you have written and explain where the problem is. While we are happy to help fix your code, we are not here to write the assignment for you.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!

Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

This isn't a complicated task if you think about it for a moment. When are the two rectangle identical? When two adjacent side lengths are the same. So take your X and Y coordinates and work out the two side lengths for each rectangle.

If the two sides are identical, or the two sides with one pair swapped are identical then so are the rectangles.

Try it on paper and you'll see what I mean.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!

Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

This isn't a complicated task if you think about it for a moment. When are the two rectangle identical? When two adjacent side lengths are the same. So take your X and Y coordinates and work out the two side lengths for each rectangle.

If the two sides are identical, or the two sides with one pair swapped are identical then so are the rectangles.

Try it on paper and you'll see what I mean.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

Permalink

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900