Well the question might seem to be very easy i.e. to print a star pattern like
1
22
333
4444
For an input of 5
But the trick is that we have to make this pattern only by completing the following lines of code:
for i in range (1,input()):
print {Here goes the code}
Code can not extend more than 2 lines
Numbers of the form
xrepeatedytimes are called repdigits. You can produce such a number simply by calculation. The challenge simplified this by asking you to produce repdigits wherex == y;yrepeats of the digity.You can produce a repeated
1,ytimes with the formula(10 ** y - 1) / 9; ten to the poweryproduces a1withyzeros. Subtract 1 and you haveynines. Divide that by9to getyones:Now all you have to do is multiply this by
yto getyrepeatedydigits:Now you have a formula for producing a repdigit for any given
y:No string operations needed; all that is needed is arithmetic operators.
Demo: