This Python program reads an even number from the user and prints the character 'B' in each line using a loop.
If the input number is odd, the program displays an error message and exits.
This exercise helps reinforce basic loop structures and conditional checks in Python.
def print_b_rows(n):
if n % 2 != 0:
print("Please enter an even number.")
return
for _ in range(n):
print("B")
# Run the program
rows = int(input("Enter an even number of rows: "))
print_b_rows(rows)
B
B
B
B
B
B
- First, the program checks whether the input number is even
- If it is, a for loop prints the character 'B' in each row
- If the number is odd, an error message is shown and the loop is skipped