+ 8
def pat(n):
if n>0 and n<=1000:
for i in range(n):
p=1
for j in range(n):
print(p,end='')
if p < n:
print('_',end='')
p=p+1
print()
n=int(input())
pat(n)
+ 1
Basically you have to add a condition that checks if it's the last line, and if it is then change the print statement.
def pat(n):
if n>0 and n<=1000:
for i in range(n):
p=1
for j in range(n):
if j != n-1:
print(p,end='_')
else:
print(p,end='')
p=p+1
print()
n=int(input())
pat(n)



