Write a program to Generate a Random Number in Python
Code:
1 2 3 4 5 6 7 8 | # Program to generate a random number between 0 and 100 # import the random module import random print(random.randint(0,100)) |
Output:
The code you provided is a simple Python program that generates a random integer between 0 and 100.
The program starts by importing the random
module, which is a standard library that provides functions for generating random numbers.
Then, the program uses the randint()
function from the random
module, which generates a random integer within a given range. In this case, the function is passed the arguments 0 and 100, so it generates a random integer between 0 and 100, inclusive.
The program then uses the print()
function to output the randomly generated integer to the console.
The output will be a random integer between 0 and 100, every time the program is run. For example, the output could be “23” or “74” or any other number between 0 and 100.