How do i do this

Joined
Jul 25, 2024
Messages
13
Reaction score
1
i am trying to create a code to make a pic using only for loops, user input and container = int
the pic looks something like this
1 = *
0 =
11111111111111111
10000000000000001
10000000000000001
10000000000000001
11111111111111111
i had to translate the pic into numbers otherwise it woudn't show right here 1 is * 0 is blankspace
 
Joined
Jul 28, 2024
Messages
2
Reaction score
0
width = int(input("Enter the width of the rectangle: "))
height = int(input("Enter the height of the rectangle: "))
char = input("Enter the character to use: ")

# Draw the filled rectangle
line = char * width
rectangle = (line + '\n') * height
print(rectangle, end='')

# Draw the rectangle with an empty middle
if width > 2 and height > 2:
# Top border
print(char * width)
# Middle part with spaces
for _ in range(height - 2):
print(char + ' ' * (width - 2) + char)
# Bottom border
print(char * width)
else:
# If width or height is too small to create an empty middle, just draw a filled rectangle again
print(rectangle, end='')
 
Joined
Jul 4, 2023
Messages
453
Reaction score
54
@PythonCoder; next time, use icon "code"
1722432479425.png


to enter the code in a more user-friendly form for other forum users, please. ;)
Python:
width = int(input("Enter the width of the rectangle: "))
height = int(input("Enter the height of the rectangle: "))
char = input("Enter the character to use: ")

# Draw the filled rectangle
line = char * width
rectangle = (line + '\n') * height
print(rectangle, end='')

# Draw the rectangle with an empty middle
if width > 2 and height > 2:
    # Top border
    print(char * width)
    
    # Middle part with spaces
    for _ in range(height - 2):
        print(char + ' ' * (width - 2) + char)
    
    # Bottom border
    print(char * width)
else:
    # If width or height is too small to create an empty middle, just draw a filled rectangle again
    print(rectangle, end='')
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,879
Messages
2,569,939
Members
46,232
Latest member
DeniseMcVi

Latest Threads

Top