The process of Python Random Numbers Generation is very simple and easy to understand.
Steps To Generate a Random Number in Python
Just follow these steps:
1. Import random module
2. Use randint() method of random module to generate an integer number within a specific range.
Example: Generate a Random Number Between 1 and 50
import random n = random.randint(1,50); print(n)
Output
44
Python Program To Generate 20 Random numbers in range of 1 to 10
We will use a for loop to generate 20 random numbers. The for loop will use the range(1,21) function for 20 iterations.
# Python program to generate 5 random numbers between 1 and 10 import random num_list = [] for i in range(1,21): n = random.randint(1,10); num_list.append(n) print("5 Random numbers between 1 to 10 are:") print(num_list)
Output
20 Random numbers between 1 to 10 are: [2, 4, 4, 1, 4, 9, 4, 9, 8, 9, 7, 6, 6, 7, 9, 10, 5, 9, 9, 2]
You may also like:
Python GUI ( Graphcal User Interface ) Programs using tkinter Module
Python GUI ( Graphcal User Interface ) Programs using tkinter Module |
- Find Factorial by Recursive Function Python GUI Program
- Multiplication Table Python GUI Program
- Python GUI Program Area of Triangle with base and height
- Python GUI Temperature Conversion Program Celsius to Fahrenhiet
- Python GUI Program Temperature Conversion Fahrenheit to Celsius
- Python Pounds to Kilogram Converter GUI tkinter Program
- Python 3 Four Function Calculator Program tkinter GUI
- Python Digital Clock Program using tkinter GUI
- Python Quotes Changer Program tkinter GUI
- Python 3 tkinter Spinbox GUI Program Example
- Python 3 tkinter Message Widget Program Examples
- Python 3 GUI Program tkinter Radio Buttons
- Adding Menus to Python 3 tkinter GUI Programs
- Python 3 GUI Program Add Two Numbers
- Explain Python grid Geometry Manager with Example Code
- Python 3 GUI Miles to Kilometers Converter tkinter Program
- Python 3 tkinter GUI Kilogram to Pounds Program
- Python Set Label Text on Button Click tkinter GUI Program
- Show Label and Button Widgets Python Tkinter Program
- Python 3 Tkinter GUI Hello World Program
- Create and Show Root Window of tkinter GUI Program