Computer Science, asked by Anonymous, 2 months ago

Solve with python programming language​

Attachments:

Answers

Answered by anindyaadhikari13
3

Answer:

This is the required program for the question in Python 3.

for i in range(6):

print("* "*(i+1),end=" ")

print(" HELLO"[i],end="")

print()

Explanation:

  • We are asked to display the given pattern. Patterns are solved using nested loops although Python has some special features due to which, we can solve the pattern in 1 loop.

  • There are six rows in the pattern. So, the loop iterates 6 times in the range I = 0 to 5.

  • Then, it prints a star (I + 1) times where I is the row number. If we multiply a string with a number (say x), then the string is repeated x times where x is the number. So, we can simply write - "* " * (i + 1)

  • Now, we will display the letters of the word HELLO. To do this, I have created a string - " HELLO". It is adjusted in such a way that the it will display the letters correctly in the given position. For example, in the string " HELLO", when i = 0, it will display a space as it is present in the 0th index. After this iteration, it displays the next letter which is at index 1 and so on.

Output:

*

* * H

* * * E

* * * * L

* * * * * L

* * * * * * O

[Program finished]

See the attachment for verification ☑.

Attachments:
Similar questions