Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array and rectangles
#1
Hello guys,

I need your help to solve this problem. I need to print a rectangle inside an another rectangle.

Example :

Input :
9 19 (number of lignes of ".", number of column of ".")
1 (number of rectangle inside)
1 3 7 5 o (lig1, col1, lig2, col2, caracter)

Output :
...................
...ooo.............
...ooo.............
...ooo.............
...ooo.............
...ooo.............
...ooo.............
...ooo.............
...................


1) Method 1 that I tried :

nbLignes, nbColonnes = map(int, input().split(" "))
nbRectangles = int(input())
tab = [ ["."] * nbColonnes] * nbLignes
for i in range(len(tab)):
    for j in range(len(tab[i])):
        print(tab[i][j], end="")
    print()
input :
9 19
1

output :
...................
...................
...................
...................
...................
...................
...................
...................
...................

I don't know how to add the second rectangles inside the first one according to the parameter we specify in the input (1 3 7 5 o). Does anyone have an idea how to do it please ?


2) Method 2 that I tried :
I tried an another version without multidimensional array but I don't know if it's the right method.

nbLignes, nbColonnes = map(int, input().split(" "))
nbRectangles = int(input())

for loop in range(nbRectangles):
    lig1, col1, lig2, col2, couleur = input().split(" ")
    
    for i in range(nbLignes):
        for j in range(nbColonnes):
            print(".", end ="")
        print()
    
    for i in range(int(lig1), int(lig2)):
        for j in range(int(col1), int(col2)):
            print(couleur, end = "")
        print()
Input :
9 19
1
1 3 7 5 o

Output :
...................
...................
...................
...................
...................
...................
...................
...................
...................
oo
oo
oo
oo
oo
oo


Thank you for your help
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,970 Dec-10-2018, 10:12 AM
Last Post: buran
  printing list of random generated rectangles Zatoichi 8 7,581 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