How can I create a window in python?

Question:

Write a program that displays a rectangle whose frame consists of asterisk ‘ * ‘ characters, the inner part of ‘ Q ‘ characters. The program will ask the user to indicate the number of rows and columns of the rectangle, these values ​​cannot be less than 3.

I tried to create various print() one below the other but I don’t understand how to make them adapt to the user, in the sense that if the user asks me for 10 lines I don’t know how to make this happen…the window should look like this:

*********************
*QQQQQQQQQQQQQQQQQQQ*
*QQQQQQQQQQQQQQQQQQQ*
*QQQQQQQQQQQQQQQQQQQ*
*********************
Asked By: thempy

||

Answers:

# Ask the user for the number of rows and columns
num_rows = int(input("Enter the number of rows: "))
num_cols = int(input("Enter the number of columns: "))

# Make sure the values are at least 3
num_rows = max(num_rows, 3)
num_cols = max(num_cols, 3)

# Print the top row of asterisks
print("*" * num_cols)

# Print the middle rows of asterisks and Qs
for i in range(num_rows - 2):
  print("*" + "Q" * (num_cols - 2) + "*")

# Print the bottom row of asterisks
print("*" * num_cols)
Answered By: mxwmnn
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.