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

I have an error and due to lack of knowledge i dont no how fix this: "Traceback (most recent call last): File "<string>", line 8, in <module>

Write code that generates a list of N elements in
range from 1 to 100. Display the list on the screen. Insert value into list
k (keyboard value) in front of all elements,
ending with the number 8.

import random

n = int (input ('Enter the number of list items') )
list = [random.randint (1, 100) for i in range (n) ]
       print (list)

number = int (input ('Enter value.') )
l = [list.index (list % 10 == 8)]

while list % 10 == 8:
 list.insert (number)

>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

You can use range() instead.

l = list(range(1,100))
print(l)
k = []
for i in l:
    if i%10==8:
        k.append(i)
print(k)
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