Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to eliminate the extra line produced by my for loop?

I am trying to print out a right-angled triangle by using a for loop, however, even though I got the shape that I intend to have, the outcome always comes with an extra line underneath the input question, I want to know how to delete it?

Here is my code:

height = int(input('Enter height: '))
for i in range(height+1):
    print(i * '*')

and the output is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Enter height: 6

*
**
***
****
*****
******

What I want to have:

Enter height: 6
*
**
***
****
*****
******

>Solution :

Your code is printing i=0, which generates the blank line.

Try the below:

height = int(input('Enter height: '))
for i in range(1, height + 1):
    print(i * '*')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading