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
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:
- START.
- Generate random integers.
- Check if they are divisible by 5 or not. If true, add them to the list.
- Continue steps 2 and 3 until the number of elements in the list becomes 20.
- Display the list.
- STOP.
Refer to the attachment for output ☑. Note that you might get different results.
Attachments:
Similar questions