On Scratch Write a script that populates a list with 15 rand

On Scratch

Write a script that populates a list with 15 random numbers in the range 10-20.

The script should delete every duplicate value in the list, so that the list contains only unique values.

Sort the resulting list in ascending order (low to high).

The initial list might look like this:
List before
19   
11
10
16
14
17
10
16   
13   
11
10
16
12
17
19

The final list would look like this:

List after:

10

11

12
13
14
16
17
19

Solution

I have created script in python. Save this file as fileName.py and run.

Script:

from random import randint
x=[]
for i in range(15):
x.append(randint(10,20))
print(\"List before:\")   
print(\'\ \'.join(\'{}\' for _ in range(len(x))).format(*x))
y=sorted(set(x))
print(\"\ List after:\")
print(\'\ \'.join(\'{}\' for _ in range(len(y))).format(*y))

On Scratch Write a script that populates a list with 15 random numbers in the range 10-20. The script should delete every duplicate value in the list, so that t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site