I want to change the length of the formatting in my code,
symbolWanted = input('Input symbol wanted for triangle: ')
baseLength = int(input('Input base length of triangle(odd number): '))
for i in range (1,baseLength,2):
print(('{:^100}').format(i*symbolWanted))
is there a way to change the length of the format using a variable e.g.
print(('{:^baseLength}').format(i*symbolWanted))
Thank you.
You can use variables in format strings:
print(('{:^{bl}}').format(i*symbolWanted, bl=baseLength))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With