Computer Science, asked by kramsha2004, 7 months ago

Q2-write
a
python code to print the pattern
22
333
4444​

Answers

Answered by hipsterizedoll410
7

Python code:

for i in range(2,5):

   print(str(i) * i)

Explanation of code:

range function ( ): It is a type of built - in function which returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number.

Range function has three parameters:

range (start,stop,step)

In this case,

range(2,5) which means, we are starting from 2 and ending it in 5. But remember, python interpreter starts taking the value from 0. Hence, it will start at 2 and end in 4.

str() function: It converts the specified value into a string.

asterisk(*) sign: In general, * sign is used as a multiplication operator but for string and tuples, it is used as a repetition operator.

Output:

22

333

4444​

More to know:

  • Python is created by Guido van Rossum and first released in 1991.
  • It is very easy to use. It is high level- interpreted language.
  • It is an open source software.
  • It is also the official language of google.
Similar questions