Answer:
The program in Python is as follows:
import math
bars = int(input("Bars: "))
symbol = input("Character: ")
current = 1
while current < bars * 2:
if current <= bars:
num = current
for i in range(num):
print(symbol,end="")
print(current)
else:
num = abs(bars * 2 - current);
for i in range(num):
print(symbol,end="")
print(i+1)
current+=1
Step-by-step explanation:
This imports the math module
import math
This gets input for the number of bars
bars = int(input("Bars: "))
This gets input for the number of characters
symbol = input("Character: ")
This sets the current element to 1
current = 1
The following iteration is repeated until printing ends
while current < bars * 2:
The following checks for printing in ascending order
if current <= bars:
num = current
The following loop prints the characters in ascending order
for i in range(num):
print(symbol,end="")
This prints the number of characters
print(current)
The following checks for printing in descending order
else:
Calculate the number of iteration left
num = abs(bars * 2 - current);
The following loop prints the characters in descending order
for i in range(num):
print(symbol,end="")
This prints the number of characters
print(i+1)
current+=1