0
Number pattern (help to correct my code)
Print the following pattern for the given N number of rows. Pattern for N = 4 1 11 202 3003 My code- n = int(input()) i=1 while i<=n: j=1 while j<=i: print(j,end='') j=j+1 print() i=i+1 On input of 2 Result- My Output 1 12 Expected Output 1 11
13 ответов
+ 2
n = int(input())
if n > 0:
print(1)
for i in range(1,n):
print(str(i)+"0"*(i-1)+str(i))
+ 2
Thank you
I have tried this code and it's running perfect.
https://code.sololearn.com/cwzsY5Ht5X1u/?ref=app
Happy coding!
+ 1
n = int(input())
i=1
while i<=n:
j=0
while j<i:
print(0 if j and j<i-1 else i-1 or 1,end='')
j=j+1
print()
i=i+1
+ 1
I've tested both...
are you sure to have correctly copyed?
+ 1
updated second one where I made a mistake ^^
do the ide wich you run the code run python3 or python2?
in python2, print must not have parenthesis ;)
+ 1
also, I don't know how to specify end parameter in python2 ;P
+ 1
what is your ide and what is exactly the runtime error message (as well as the input provided)?
+ 1
# have you tried the other shorter code and does it produce also error?
# else try with:
n = int(input())
i=1
while i<=n:
j=0
while j<i:
if i==1:
print(1, end="\n")
elif j and j<i-1:
print(0, end="\n")
else:
print(i-1, end='')
j=j+1
print()
i=i+1
0
@visph
It's showing runtime error
0
But ide on which I am running this program is throwning error.
However on sololearn your program is running perfect.
But for an input of 2 at place of 22 output must be 11.
https://code.sololearn.com/cnMJelsbmw9i/?ref=app
0
I am using python 3.5
0
I'm using coding ninjas ide
Here is the input and output
https://ibb.co/fCFPK72
0
a=int(input('enter the number'))
for i in range(a):
if i!=1:
j=i-1
print(i,j*'0',i)
else:
print(i)
print(i,i)