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

Why it just gives me nothing?

I wanted to make a list in put in it some variables, but when I start this code it’s just closing. I am new in python (and coding at all) so what’s wrong with code?


sh = 8
sm = 15
length = 45


sme = sm + length
sme *= 7
num = list(range(sm,sme,length))
ns = 1
n1 = 2 * ns
n2 = 5 * ns
n3 = 8 * ns 
for i in num:
     num.insert(n1, n1 + 5)
     num.insert(n2, n2 + 10)
     num.insert(n3, n3 + 15)
     if ns == 1:
         ns += 2
     elif ns%3 == 0: 
         ns += 3
print(num)

>Solution :

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

Well, your loop is never-ending since you keep increasing the num’s length.
So, just loop till the definite length of num.

sh = 8
sm = 15
length = 45


sme = sm + length
sme *= 7
num = list(range(sm,sme,length))
ns = 1
n1 = 2 * ns
n2 = 5 * ns
n3 = 8 * ns 
for _ in range(len(num)): # Here you are providing a definite(or original length to `for loop`)
     num.insert(n1, n1 + 5)
     num.insert(n2, n2 + 10)
     num.insert(n3, n3 + 15)
     if ns == 1:
         ns += 2
     elif ns%3 == 0: 
         ns += 3
print(num)
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