On this code, if that is true for all characters, but only if I put character: %%, it fails the program. It is expected to have no triangle at all since the height = 0. Can you help me to fix it on this code?
#take input
h=int(input("Enter height of triangle: "))
c=input("Character: ")
#check for -ve h
if h<=0:
h=3
#check for c
#remove whitespaces
c=c.replace(" ","")
#if c has no or multiple characters
if c=="":
c="*"
if len(c)>1:
c=c[0]
#Print triangle
for i in range(h):
for j in range(h-i): #print required space before character
print(" ", end='')
for j in range(2*i+1):
if j==0 or i==h-1 or j==2*i:
print(c, end='')
else:
print(' ',end='')
for j in range(h-i):
print(' ',end='')
print() #next line
On this code, if that is true for all characters, but only if I put character: %%, it fails the
Step by step
Solved in 3 steps with 5 images