Python SolutionsPython Solutions
👉
Right-Align
Week 22, 2026
All SolutionsPython - Print Spaces and Single Loop | BMC | Python Solutions
def rightAlign(msg:str, lineWidth:int, startingChars:int, CharStep:int) -> None:
first = msg[0:startingChars]
spaces = lineWidth-startingChars
msg = msg[startingChars:len(msg)]
# print first line
print(" "*spaces, end="")
print(first)
# print rest
i = 0
while i < len(msg):
startingChars += CharStep
spaces = spaces-CharStep
print(" "*spaces, end="")
print(msg[i:i+startingChars])
i += startingChars
# main
msg = "We do not inherit the Earth from our ancestors; we borrow it from our children. Every part of this Earth is sacred, and we must care for it as we would care for our own lives - Chief Seattle"
rightAlign(msg, 20, 1, 1)
print()
rightAlign(msg, 10, 1, 0)
print()
rightAlign(msg, 50, 50, -6)