This Python program reads a number from the user to determine how many lines to print.
In each line, it displays a sequence of 'x' characters, one for each character in a sample text.
This exercise helps practice nested loops and character-level output formatting in the terminal.
def display_text_with_x(rows, text="Hello"):
for i in range(rows):
for char in text:
print("x", end="")
print()
# Run the program
rows = int(input("Enter number of lines: "))
display_text_with_x(rows)
xxxxx
xxxxx
xxxxx
- The program reads the number of lines from the user
- A nested loop is used: the outer loop controls the number of lines
- The inner loop iterates over each character in the sample text
- Instead of printing the actual character, it prints 'x' for each one
- The result is a grid of 'x' characters, matching the length of the text