0% found this document useful (0 votes)
5 views1 page

Using Python Libraries

The document discusses a Python code fragment that uses the random library to generate a random number. The output of the code will be a value between 18 and just under 23, as it adds 18 to a random number between 0 and less than 5. It explains the use of the dot operator to access functions from libraries in Python.

Uploaded by

Sanjeev Bora
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Using Python Libraries

The document discusses a Python code fragment that uses the random library to generate a random number. The output of the code will be a value between 18 and just under 23, as it adds 18 to a random number between 0 and less than 5. It explains the use of the dot operator to access functions from libraries in Python.

Uploaded by

Sanjeev Bora
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

DAV Centenary Public School, Haldwani

Class: XII, (Session: 2023-24), Sub: Computer Science


Topic: Using Python Libraries
Q1: What will be the possible output of following code fragment?
import random
print(18 + [Link]()*5)
Ans:
[Link]( ) means to use random( ) function of random module(library).
Whenever we use library function of other libraries then we have to use .(dot) operator
with name of module.
random( ): random( ) will generate random numbers greater than equal to 0 and less than
1
when it is multiplied with 5, the range becomes 0.0 to less than 5(<5)
When 18 is added to it, the range becomes 18 to <23

You might also like