How to Add Random Numbers to the List in Python


Here we will get the methods to generate random numbers from 1 to 30 and add them to the list.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import random

n = int(input("Please input the number of elements: "))
a = [random.randint(1, 30) for i in range(n)]
print("The random list is: ", a)

Output:

Please input the number of elements: 10
The random list is: [4, 10, 10, 25, 22, 27, 19, 4, 5, 8]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments