Revised Python Modules XI CSc (1)
Revised Python Modules XI CSc (1)
www.knowpythonbytes.blogspot.com
OUTPUT
OUTPUT
RENAMING/ALIASING A MODULE
• As per programmer’s requirement, one can rename the name of a
module i.e give a short new alias name to the module.
• It can be used only within the program wherever it has been renamed.
Here, m is the alias
name used for the
math module.
Python
Interpreter
first look in
the current
directory
when
trying to
do an
import.
DATA HANDLING WORKING WITH
MATH MODULE
Some mathematical functions in math module are:
Write this statement before using the following functions in the
math module.
HINT:
Imagine a room between the two integer points on the y axis where the
given value will lie.
ceiling
Now, the integer value which comes in the ceiling of the room is the
- 2.7
answer for ceil function . Similarly integer value which comes in the floor
floor of the room is the answer for floor function.
FUNCTION Prototype Description
(General form)
math.exp(arg) The exp() function returns the
exp natural logarithm e raised to
the arg power
Value of e is 2.718
math.sin(arg) The sin() functions returns the
sin sine of arg.the value of arg must
be in radians.
u*t+(1/2)*f*math.pow(t,2)
**COMPOSITION:
ii) |e2y-x| Composition is an art of combining simple
function(s) to build more complicated ones,
Ans.
math.fabs(math.exp(2*y)-x) i.e., result of one function is used as the input
to another. Here, result of math.exp() is input
to the function math.fabs()
TIME TO SOLVE……………
Q1) Give the output for the print Q2) Write the corresponding Python
Expressions from the mathematical
statements expressions:
import math
i) |a|+b >= |b|+a
a=math.pow(2,5)
print(a) ii)
print(math.sqrt(81))
print(math.ceil(12.8)) (iii) Cos(x) - 5x
Tan(x)
print(math.floor(12.8)
print(math.ceil(-38.5)) iv) p+ q
(r+s) 4
print(math.floor(-38.5))
import random module
The random module is a built-in module in Python to
generate the pseudo-random numbers.
Random numbers are used in various fields like in
Science, Art, Statistics, cryptography, gaming and
many other fields.
USES OF RANDOM NUMBERS (Some examples)
Captcha
Automatic password generator
Keys for encryption
Random module functions Example
random() The random() method returns a float number between
0.0 to 1.0 i.e. (0<=N<1) This function does not take any initial value as an
argument.Here, in the example, output of a can be 0.0, 0.1,0.12 …and so on
infinite numbers between 0.0 and 1.0 but, it will never get the value 1.0
0,1,2,3,4,5,6,7,8,9
10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
10,13,16,19,22
randint() function
CANNOT take step values
import statistics
Python statistics module is used to calculate mathematical statistics of numeric
data. For eg. mean(),median(),mode(),stdev() functions under statistics module.
APPLICATION OF STATISTICS
LET US RECALL mean(),median(),mode(),stdev() learnt in Mathematics
Find the mean, median and
mode of the sequence
19,12,9,5,8,5,25,8
SOLUTION:
mean()
median()
mode()
stdev()
Here, St is the alias name used for the statistics module.
Here, L is the List sequence used as the function argument.
Bibliograhy and References
• Google
• Wikipedia
• Quora
• XI Computer Science , By Sumita Arora, Dhanpat Rai
Publication 2020 Edition
• XI Informatics Practices , By Sumita Arora, Dhanpat Rai
Publication 2020 Edition
Stay safe. Stay aware. Stay healthy. Stay alert.
Programming is an ART….
Add your colours to it and make your own