This is a Python Program to generate random numbers from 1 to 20 and append them to the list.
The program takes in the number of elements and generates random numbers from 1 to 20 and appends them to the list.
1. Import the random module into the program.
2. Take the number of elements from the user.
3. Use a for loop, random.randint() is used to generate random numbers which are them appending to a list.
4. Then print the randomised list.
Here is source code of the Python Program to generate random numbers from 1 to 20 and append them to the list. The program output is also shown below.
n=int(input(“Enter number of elements:”))
for j in range(n):
print(‘Randomised list is: ‘,a)
Runtime Test Cases
Enter number of elements:3
(‘Randomised list is: ‘, [17, 4, 9])
Enter number of elements:7
(‘Randomised list is: ‘, [16, 5, 18, 19, 6, 7, 20])