Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array and rectangles
#4
You do not need a multi-dimensional array. You need to write a function that will tell you if x, y is part of a rectangle.

To do this you need a data structure that can store your rectangle. The code below saves rectangle information in a dictionary. You could also use a list or a tuple or a class:
line = input('Input rectangle coordinates x1 y1 x2 y2 pixel:')
v = line.split()
rect = {'x1':v[0], 'y1':v[1], 'x2':v[2], 'x3':v[3], 'pixel':v[4]}
You need to support having multiple rectangles, so you will have to store all the rectangles in a list.

A good next step is modifying your program so you can enter multiple rectangles and save them all in a list. Print out the list to verify the information was saved correctly.
Reply


Messages In This Thread
Array and rectangles - by pythonuser1 - Apr-24-2020, 12:21 PM
RE: Array and rectangles - by deanhystad - Apr-24-2020, 01:18 PM
RE: Array and rectangles - by pythonuser1 - Apr-24-2020, 03:30 PM
RE: Array and rectangles - by deanhystad - Apr-24-2020, 04:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to generate multiple rectangles with randrange without overlapping? rafaberec 1 1,889 Dec-10-2018, 10:12 AM
Last Post: buran
  printing list of random generated rectangles Zatoichi 8 7,385 Feb-18-2018, 06:34 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020