12.0k views
6 votes
Write a program that fills a list with 100 random numbers between 0 and 200, inclusive. Traverse through the list and only print out the numbers that are less than 99. You can develop this code in App Lab if you like and copy your final program to the answer area below. Keep the code neat and use curly braces where necessary. This question is worth 4 points. *

User Heathesh
by
3.8k points

1 Answer

2 votes

Answer:

Follows are the code to this question:

import random as ra#import package

r=[ra.randint(0, 200) for x in range(100)]#defining a variable r that use rand method to add value in list

j= [i for i in r if i < 99]#defining j variable that checks list value is less than 99

print (j)#print list value

Output:

[20, 23, 66, 47, 89, 7, 18, 13, 92, 31, 23, 60, 3, 52, 18, 20, 85, 64, 55, 98, 14, 80, 80, 14, 57, 92, 76, 14, 91, 83, 87, 80, 16, 50, 7, 88, 19, 4, 72, 23, 27, 79, 23]

Step-by-step explanation:

In this code, package random is imported, in the next step, the r variable is declared, that uses the randit method, and use for loop that adds value in the list. In the next step, the j variable is declared, which uses a for loop and a conditional statement to check its value is less than 99, add print its value.

User Ziligy
by
4.5k points