how can I justify the output of this code?
N = int(input())
case = '#'
print(case)
for i in range(N):
case += '#'
print(case)
You can use format
with >
to right justify
N = 10
for i in range(1, N+1):
print('{:>10}'.format('#'*i))
Output
#
##
###
####
#####
######
#######
########
#########
##########
You can programattically figure out how far to right-justify using rjust
as well.
for i in range(1, N+1):
print(('#'*i).rjust(N))
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