Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4
What Deep said. def pat(n): for i in range(0,n): for j in range(0,n): print(n) print("\r") n=int(input()) pat(n) BTW a couple of streamlining points - since 0 is the default start for range(), all you need to say is 'range(n)'. Also, since print() automatically ends with a carriage return (unless you tell it to end with something else using end=), you don't need the "\r" - just 'print()' does the same thing.
21st Jul 2017, 5:50 AM
David Ashton
David Ashton - avatar
+ 4
This works. There may be a shorter way to do it but I couldn't think of one 🙂 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)
21st Jul 2017, 2:00 PM
David Ashton
David Ashton - avatar
+ 2
Check David's Code. That's what I meant. First accept the value of 'n', and then pass it into the function.
21st Jul 2017, 5:59 AM
Deep chand
Deep chand - avatar
+ 1
Buddy, you gotta follow the special rule of Python. Check this out. def add(a, b): print("Addition of given numbers: ") print(a+b) add(3,5) add(2,2) #See that gap? Intended space. Python needs to #know which statement belongs to which function. #Hope you get it. Otherwise I'll show you an another #example.
21st Jul 2017, 4:57 AM
Deep chand
Deep chand - avatar
+ 1
Bro, you need to accept the value of 'n' to pass that as a parameter, right? But you'd write that unit inside the function. Write outside the function and pass it as a parameter.
21st Jul 2017, 5:35 AM
Deep chand
Deep chand - avatar