0% found this document useful (0 votes)
30 views4 pages

Aaaaa

The document discusses Python modules and how to use them. It shows how to import built-in modules like math, random, and statistics and use functions from them. It also demonstrates how to create custom modules with user-defined functions and import/use those functions in other programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Aaaaa

The document discusses Python modules and how to use them. It shows how to import built-in modules like math, random, and statistics and use functions from them. It also demonstrates how to create custom modules with user-defined functions and import/use those functions in other programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CLASS XI NOTES ON PYTHON MODULES

import math
print(math.pi)
print(math.e)
print(math.sqrt(25))
print(math.ceil(5))
print(math.floor(8))
print(math.pow(4,3))
print(math.fabs(3))
print(math.sin(30))
print(math.cos(60))
print(math.tan(45))
Output:
3.14159265359
2.71828182846
CLASS XI NOTES ON PYTHON MODULES

5.0
5.0
8.0
64.0
3.0
-0.988031624093
-0.952412980415
1.61977519054

import random
print(random.random())
#The function generates any random number between 0 to 10
print(random.random()*10)
#The second line of code generated a random number between 10 to 25. #random() *
(upperrange - lowerrange) +lowerrange)
print(random.random()*(25-10)+10)
#The randint(a,b) function requires two parameters i.e. upper limit and lower limit
numbers to generate a series
print(random.randint(10,25))
#This function accepts the start, stop, and step values to generate random number by a
specified series.:
randrange(start, stop, step)'''
print(random.randrange(3, 9))
print(random.randrange(3, 9,2))
#The mean() function computes the average or mean of the given set of numbers
import statistics
print(statistics.mean([23,23,23,20]))

#It calculates the median (middle) values of given dataset. Observe the following code and output:
print(statistics.median([1, 3, 5, 7, 9]))
print(statistics.median([2, 4, 6, 8, 10, 12]))
#mode() function most common data in the list
print(statistics.mode(['India','UK','Pak','India']))
print(statistics.mode([23,22,22,21,20]))
CLASS XI NOTES ON PYTHON MODULES

def sum():
a=int(input("Enter first number"))
b=int(input("Enter second number"))
result=a+b
print("sum of %d and %d is %d"%(a,b,result))
______________________________________

import sum_module
sum_module.sum()

# creating module/function with three airthmetic operations (+,* and /)


def sum(a,b):
result= a+b
return result
def mul(a,b):
result= a*b
CLASS XI NOTES ON PYTHON MODULES

return result
def div(a,b):
result= a/b
return result

__________________________________________________________________________

# importing calculator module


import calculator
a=int(input("Enter first number"))
b=int(input("Enter second number"))
print ("sum of entered numbers",calculator.sum(a,b))
print ("multiplication of entered numbers",calculator.mul(a,b))
print ("division of entered numbers",calculator.div(a,b))
_________________________________________________________________________

The from import Statement


from calculator import sum
sum(10,12)

The from module import * Statement


from calculator import *
sum(10,12)
mul(5,7)
div(6,3)

You might also like