Computer Science, asked by dgrovers067, 4 months ago

Write a program to generate 20 random numbers from 100 to 500 and store them in a list if they are

divisible by 5.​

Answers

Answered by anindyaadhikari13
2

Required Answer:-

Question:

  • Write a program to generate 20 random numbers from 100 to 500 and store them in a list if they are divisible by 5.

Solution:

Here comes the program.

import random

c=0

l=[]

while c<20:

x=random.rándint(100,500)

if x%5==0:

 l.append(x)

 c+=1

print("Here comes the list.")

print(l)

Algorithm:

  1. START.
  2. Generate random integers.
  3. Check if they are divisible by 5 or not. If true, add them to the list.
  4. Continue steps 2 and 3 until the number of elements in the list becomes 20.
  5. Display the list.
  6. STOP.

Refer to the attachment for output ☑. Note that you might get different results.

Attachments:
Similar questions