0% found this document useful (0 votes)
1 views2 pages

25) - Module

The document outlines a Python class session covering random number generation, module creation, and usage. It includes examples of importing and using custom modules like 'one', 'stats', and 'circle', along with functions for statistical calculations and geometric area. Additionally, it explains the special variable __name__ and its behavior when running a script directly versus as a module.

Uploaded by

mohit
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)
1 views2 pages

25) - Module

The document outlines a Python class session covering random number generation, module creation, and usage. It includes examples of importing and using custom modules like 'one', 'stats', and 'circle', along with functions for statistical calculations and geometric area. Additionally, it explains the special variable __name__ and its behavior when running a script directly versus as a module.

Uploaded by

mohit
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

THE PYTHON CLASS

(Session 25, 13th Aug 2021)

Topics - Module
_____________________________________________________________________________________________

import random
print([Link]()) # generates float value 0-1 (0,1 not inclusive)
print([Link](1,10)) # 10-inclusive
names = ['python', 'java', 'C#', 'C++']
print([Link](names)) # returns random obj from list

x = [Link]()
print(round(x, 3))

names = ['python', 'java', 'C#', 'C++']


print('java' in names)

Creating and Using our own modules -

import one
[Link]()
print([Link])

from stats import *


numbers = [1,1,1]
sd = calculatesd(numbers)
print(sd)

import circle
print([Link](2))

[Link] -
var = 1

print('Hey')

def some():
print('-')

[Link]-
import math

def getmean(numbers):
average = sum(numbers)/len(numbers)
return average
def getdeviations(numbers, mean):
deviations = []
for number in numbers:
[Link](mean-number)
return deviations

def getsqrdeviations(deviations):
sqrdeviations=[]
for deviation in deviations:
[Link](deviation**2)
return sqrdeviations

def getvar(sqrdeviations):
var = getmean(sqrdeviations)
return var

def getsd(var):
sd = [Link](var)
return sd

def calculatesd(numbers):
mean = getmean(numbers)
deviations = getdeviations(numbers, mean)
sqrdeviations = getsqrdeviations(deviations)
var = getvar(sqrdeviations)
sd = getsd(var)

return sd

[Link] -
def calcdia(r):
return r**2

def peri(r):
return 2*3.14*r

def area(r):
return 3.14*r*r

if __name__ == '__main__':

print(calcdia(2))
print(peri(2))
print(area(2))

There’s a special var __name__. It can store different values depending on how this file is being used.
When you’re directly running your file, __name__ with have value __main__
When you’re using this as module in some other file, __name__ with have value filename

_____________________________________________________________________________________________

You might also like