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

Each group of five stars separated by a vertical line

I’m a new one at the world of Python programming and I just, unfortunately, stuck on this, I think, simple exercise.

So what I should do is to modify the stars(n) function to print n stars, with each group of five stars separated by a vertical line.
I have code like this, but I really don’t know what to do with it.

def stars(n):
    for i in range(n):
        print("*", end='')
        if i == 4:
            print("|", end="")

    print()

stars(7)
stars(15)

The output should be like that:

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

*****|**
*****|*****|*****|

>Solution :

The problem is in the condition. This code should do:

def stars(n):
for i in range(n):
    print("*", end='')
    if i % 5 == 4:
        print("|", end="")

print()
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