N.S.S. COLLEGE, CHERTHALA
DEPARTMENT OF MATHEMATICS
MM 1645: COMPUTER PROGRAMMING

II
PRACTICAL RECORD
Name of the Candidate
: ____________________________________________
Register Number
: ____________________________________________
Programme
: ____________________________________________
No. of Experiments
: ____________________________________________
Head of the Department
Faculty

in

Charge
Bona fide certified hereby that
Examiners:
1.
2.
CONTENTS
PART

I: LATEX
No.
Title of the Experiment
Page #
Date
1
Typesetting a Simple Document
3
12/12/12
2
Typesetting a Certificate
5
12/12/12
3
Typesetting the Certificate with large headlines
7
17/12/12
4
Typesetting a Simple Paragraph
9
17/12/12
5
Typesetting a Simple
Paragraph
11
17/12/12
6
Typesetting a Simple Paragraph
13
17/12/12
7
Typesetting Table columns without boarder lines
15
03/01/13
8
Typesetting Table columns without boarder lines
17
03/01/13
9
Typesetting a Simple Mathematics equation
20
14/01/13
10
Typesetting a Simple Mathematics Text
22
14/01/13
11
Typesetting a Simple Mathematics Theorem
24
28/01/13
12
Typesetting a Simple Research Paper
29
28/01/13
13
Different available Fonts in Tex
31
06/02/13
14
Different available Line Spacing in Tex
34
13/02/13
15
Typesetting a Sample Math Question Paper
36
20/02/13
Table of Latex commands for Math symbols
40
27/02/13
PART

II: PYTHON
No.
Title of the Experiment
Page #
Date
1
Python as a calculator to compute Simple Interest
46
01/03/13
2
Python as a calculator for temperature conversion
47
01/03/13
3
Program to find the GCD of two given numbers
48
04/03/13
4
Program to check whether a given number is even
49
04/03/13
5
Program to
check the primality of a given integer
50
06/03/13
6
Program to
list primes in a given range by SoE
51
06/03/13
7
Program to
generate terms of Fibonacci sequence
52
08/03/13
8
Program to slice/append words by string operations
53
08/03/13
9
Program to reverse the digits of a given number
54
11/03/13
10
Program to
sort a list of numbers or names
55
11/03/13
11
Program to find the norm of partition of an interval
56
12/03/13
12
Program to
find the angle & dot

product of vectors
57
12/03/13
13
Program to
solve an equation by Bisection method
58
14/03/13
14
Program to
solve by Regula

Falsi method
59
14/03/13
15
Program to
solve by Newton

Raphson method
60
25/03/13
16
Program to
evaluate integral by Trapezoidal rule
61
25/03/13
17
Program to
evaluate integral by Simpson’s 1/3 rule
62
26/03/13
18
Program to
evaluate integral by Simpson’s 3/8 rule
63
26/03/13
19
Program to
solve first order ODE by Euler method
64
27/03/13
20
Program to
solve first order ODE by RK method
65
27/03/13
PART

I
LATEX PROGRAMMING
1. Typesetting a simple Document
1document.tex
\
documentclass{article}
\
begin{document}
This is my
\
emph{first}experiment with
\
LaTeX
\
end{document}
2. Typesetting a Certificate
2certificate.tex
\
documentclass{article}
\
begin{document}
\
begin{center}
The
\
TeX nical Institute
\
\
[10pt]
Certificate
\
end{center}
\
noindent This is to certify that Mr.N.O.Vice has undergone a course at this
institute and is qualified to be a
\
TeX nician.
\
begin{flushleft}
\
today
\
end{flushleft}
\
begin{flushright}
The Director
\
\
The
\
TeX nical Institute
\
end{flushright}
\
end{document}
3. Typesetting the certificate with large headlines
3certificate.tex
\
documentclass[a4paper,12pt]{article}
\
usepackage[margin=3cm]{geometry}
\
begin{document}
\
begin{center}
\
large
\
textbf{The
\
TeX nical institute}
\
\
[10pt]
\
Large
\
textsc{Certificate}
\
end{center}
\
noindent This is to certify that Mr.N.O.Vice has undergone a course at this
institute and is
qualified to be a
\
TeX nician.
\
begin{flushleft}
\
today
\
end{flushleft}
\
begin{flushright}
The director
\
\
The
\
TeX nical Institute
\
end{flushright}
\
end{document}
4. Typesetting a simple Paragraph
4paragraph.tex
\
documentclass{article}
\
begin{document}
Digital information technology contributes to the world by making it
easier to copy and modify information. Computers promise to make this easier for
all of us. Not everyone wants it to be easier. The system of copyright gives
software pro
grams "owners", most of whom aim to withhold software's potential
benefit from the rest of the public.
They would like to be the only ones who can copy and modify the software that
we use. The copyright system grew up with printing

a technology for mass
production copying. Copyright fit in well with this technology because it restricted
only the mass producers of copies. It did not take freedom away from readers of
books. An ordinary reader, who did not own a printing press, could copy books
only with pe
n and ink, and few readers were sued for that.
\
end{document}
5. Typesetting a simple Paragraph
5paragraph.tex
\
documentclass{article}
\
begin{document}
Digital information technology contributes to
the world by making it
easier to
copy and modify information.
\
\
Computers promise to make this
easier for all of us. Not everyone wants it to be easier. The system
of copyright gives software programs "owners", most of whom aim to withhold
software's potential benefit from the rest of
the public.
They would like to be the only ones who can copy and modify the software that
we use.The copyright system grew up with printing

a technology for mass
production copying.Copyright fit in well with
this technology because it restricted only
the mass producers of copies. It did not
take freedom away from readers of books. An ordinary reader, who did not own a
printing press, could copy books
only with pen and ink, and few readers were sued for that.
\
end{document}
6.
Typesetting a simple Paragraph
6paragraph.tex
\
documentclass[a4paper]{article}
\
begin{document}
\
noindent Digital information technology contributes to
the world by making it
easier to copy and modify information.Computers promise to make this easier f
or
all of us.Not everyone wants it to be easier. The system
of copyright gives software programs "owners", most of whom aim to withhold
software's potential benefit from the rest of
the public.
They would like to be the only ones who can copy and modify
the software that
we use. The copyright system grew up with printing

a technology for mass
production copying. Copyright fit in well with this technology because it restricted
only the mass producers of copies. It did not take freedom away from readers
of
books. An ordinary reader, who did not own a printing press, could copy books
only with pen and ink, and few readers were sued for that.
\
end{document}
7. Typesetting table columns without boarder lines
7table.tex
\
documentclass{article}
\
begin{document}
\
begin{center}
\
begin{tabular}{cr}
Planet & Diameter(km)
\
\
[5pt]
Mercury & 4878
\
\
Venus & 12104
\
\
Earth & 12756
\
\
Mars & 6794
\
\
Jupiter & 142984
\
\
Saturn & 120536
\
\
Uranus & 51118
\
\
Neptune & 49532
\
\
Pluto & 2274
\
\
\
end{tabular}
\
end{center}
\
end{document}
8. Typesetting table columns without boarder lines
8table.tex
\
documentclass{article}
\
begin{document}
\
begin{center}
\
begin{tabular}{cr}
Planet & Diameter(km)
\
\
[5pt]
Mercury & 4878
\
\
Venus &
12104
\
\
Earth & 12756
\
\
Mars & 6794
\
\
Jupiter & 142984
\
\
Saturn & 120536
\
\
Uranus & 51118
\
\
Neptune & 49532
\
\
Pluto & 2274
\
\
\
end{tabular}
\
end{center}
\
begin{center}
\
begin{tabular}{lr}
\
hline
Planet & Diameter(km)
\
\
\
hline
Mercury &
74878
\
\
Venus & 12104
\
\
Earth & 12756
\
\
Mars & 6794
\
\
Jupiter & 142984
\
\
Saturn & 120536
\
\
Uranus & 51118
\
\
Neptune & 49532
\
\
Pluto & 2274
\
\
\
hline
\
end{tabular}
\
end{center}
\
begin{center}
\
begin{tabular}{lr}
\
hline
Planet & Diameter(k
m)
\
\
\
hline
Mercury & 4878
\
\
\
hline
Venus & 12104
\
\
\
hline
Earth & 12756
\
\
\
hline
Mars & 6794
\
\
\
hline
Jupiter & 142984
\
\
\
hline
Saturn & 120536
\
\
\
hline
Uranus & 51118
\
\
\
hline
Neptune & 49532
\
\
\
hline
Pluto & 2274
\
\
\
hline
\
end{tabular}
\
end{center}
\
end{document}
9. Typesetting a simple Mathematics equation
9matheqn.tex
\
documentclass{article}
\
begin{document}
If $ a $ and $ b $ are real numbers,
then
\
[
(a+b)^2=a^2+2ab+b^2
\
]
\
end{document}
10. Typesetting a simple Mathematics Text
10mathtext.tex
\
documentclass{article}
\
usepackage{amsmath}
\
newcommand{
\
norm}[1]{
\
ensuremath{
\
left
\
vert,#1,
\
right
\
vert}}
\
begin{document}
Let $X$ and $Y$ be normed linear spaces over $k$
and let $T:X
\
to Y$ be
linear operator.If there exist $c>0$ such that
\
begin{equation}
\
norm{Tx}
\
le c
\
norm{x}
\
quad
\
text{for every}
x
\
text{in}X
\
end{equation}
then we say that $T$ is a
\
emph{bounded
linear operator} from $X$ into $Y$ and we define
\
begin{equation}
\
norm{T}=
\
sup
\
l
eft
\
{
\
frac{
\
norm{Tx}}{
\
norm{x}}
~:x
\
in X,x
\
ne 0
\
right
\
}
\
end{equation}
called the norm of the operator $T$
\
end{document}
11. Typesetting a simple Mathematics Theorem
11theorem.tex
\
documentclass[12pt,a4paper]{book}
\
usepackage{amsmath,amssymb}
\
usepackage{amsthm}
\
usepackage{mathrsfs}
\
newtheorem{thm}{Theorem}
\
newtheorem{defn}{Definition}
\
newtheorem{rem}{Remark}
\
newtheorem{exa}{Example}
\
newtheorem{corr}{Corollory}
\
newtheorem{res}{Result}
\
pagenumbering{
roman}
\
begin{document}
\
chapter{Connectedness}
\
section{Connected Spaces}
A topological space $X$ is said to be connected if it cannot be represented as the
union of two disjoint nonempty open sets.
Otherwise if $X=A
\
cup B$, where $A$ and $B$ are disjoint, nonempty and open,
then $X$ is said to be disconnected and $A,
\
: B$ is called a `disconnecction' or a
`separation' of $X$.
Connectedness of a space can be characterised as follows
\
begin{thm}
A
space $X$ is connected iff the only subsets of $X$ that are both open and
closed in $X$ are the empty set and $X$ itself.
\
end{thm}
\
begin{proof}
Suppose $A$ is a nonempty open subset of $X$, that is both open and closed in
$X$.
Consider $A$ and $B$
where $B=X

A.$ Then $A$ and $B$ are open, nonempty
and disjoint subsets of $X$.
$A $ is open by assumption; $B$ is open, since $A$ is closed. Also since $A$ is a
nonempty open subset of $X$, $X

A= B$ is nonempty. Also $X=A
\
cup B $
$
\
Rightarrow X $ is
disconnected.
Conversely, suppose $X$ is disconnected with $A,B$ as a disconnection.
Then $X=A
\
cup B $ where $ A, B $ are open, $A
\
cap B=
\
emptyset$ and
$A
\
neq
\
emptyset , B
\
neq
\
emptyset $.
Now $A=X

B
\
Rightarrow A$ is closed.
Thus $A$ is a nonempty
proper subset of $X$, which is both open and closed.
\
end{proof}
\
begin{defn}
\
noindent A connected subspace of $X$ is a subspace $Y$ which is connected as a
topological space in its own right.
\
end{defn}
This is equivalent to the condition that
\
beg
in{thm}
A subspace $Y$ of $X$ is connected if $Y$ is not contained in the union of two
open subsets of $X$, whose intersection with $Y$ are disjoint and nonempty.
\
end{thm}
\
begin{proof}
For if $Y$ is not connected with $A,B$ as a separation, then
$$Y
=A
\
cup B$$
$A,
\
: B$ are nonempty sets with $A
\
cap B=
\
emptyset $.
By the definition of relative topology on $Y$,
$$A=Y
\
cap C
\
quad
\
textrm {and}
\
quad B=Y
\
cap D$$
where $C,D$ are open in $X$. Then
$$Y=(Y
\
cap C)
\
cup (Y
\
cap D)$$
Thus $Y$ is contained in the union of two open subsets of $X$, whose intersection
with $Y$ are disjoint and nonempty.
\
end{proof}
\
end {document}
12. Typesetting a simple Research Paper
12RPaper.tex
\
documentclass{book}
\
title{This is a Res
earch Paper}
\
author{Dr.Janard Sureshkumar
\
\
Dept of Mathematics, N.S.S.College
\
footnote{Mob. 9496590767}}
\
date{
\
today}
\
begin{document}
\
maketitle
\
chapter{
\
TeX}
\
section{Just what is
\
TeX}
\
TeX{} {
\
LARGE$ =
\
tau
\
epsilon
\
chi$ (tau epsilon chi)}, is
a computer
language designed for use in typesetting; in particular, for typesetting math and
other technical (from greek ``techne" = art/craft, the stem of `technology')
material.
In the late 1970s, Donald Knuth was revising the second volume of his
multivolume magnum opus The Art of Computer Programming, got the galleys,
looked at them, and said (approximately) "blecch"! He had just received his first
samples from the new typesetting system of the publisher's, and its quality was so
far below that of
the first edition of Volume 2 that he couldn't stand it. Around the
same time, he saw a new book by Patrick Winston that had been produced
digitally, and ultimately realized that typesetting meant arranging 0's and 1's (ink
and no ink) in the proper patte
rn, and said (approximately), "As a computer
scientist, I really identify with patterns of 0's and 1's; I ought to be able to do
something about this", so he set out to learn what were the traditional rules for
typesetting math, what constituted good typog
raphy, and (because the fonts of
symbols that he needed really didn't exist) as much as he could about type design.
He figured this would take about 6 months. (Ultimately, it took nearly 10 years,
but along the way he had lots of help from some people who
are well known to
many readers here
—
Hermann Zapf, Chuck Bigelow, Kris Holmes, Matthew
Carter and Richard Southall are acknowledged in the introduction to Volume E,
Computer Modern Typefaces, of the Addison

Wesley Computers and Typesetting
book series.)
\
e
nd{document}
13. Different available fonts in Tex
13fonts.tex
\
documentclass[a4paper,12pt]{article}
\
usepackage{multirow, array}
\
newcolumntype{L}{>{
\
large}c<{}}
\
renewcommand{
\
arraystretch}{1.2}
\
begin{document}
\
section{font sizes}
The available
font sizes are
\
texttt{10pt, 11pt, 12pt}
\
section{font sizes}
\
begin{tabular}{llll}
\
hline
\
tiny India
&
\
verb
\
tiny India 
&
\
large India
&
\
verb
\
large India 
\
\
\
scriptsize India
&
\
verb
\
scriptsize India 
&
\
Large India
&
\
verb
\
Large I
ndia 
\
\
\
footnotesize India &
\
verb
\
footnotesize India 
&
\
LARGE India
&
\
verb
\
LARGE India 
\
\
\
small India
&
\
verb
\
small India 
&
\
huge India
&
\
verb
\
huge India 
\
\
\
normalsize India
&
\
verb
\
normalsize India 
&
\
Huge India
&
\
verb
\
Huge India 
\
\
\
hline
\
end{tabular}
\
section{Font styles}
\
begin{tabular}{Llll}
\
textbf{India}
&
\
verb
\
textbf{ India}
&
\
bfseries India
&
\
verb
\
bfseries India 
\
\
\
textsc{ India}
&
\
verb
\
textsc{ India}
&
\
scshape India
&
\
verb
\
s
cshape India 
\
\
\
textit{ India }
&
\
verb
\
textit{ India }
&
\
itshape India
&
\
verb
\
itshape India 
\
\
\
textsl{ India }
&
\
verb
\
textsl{ India }
&
\
slshape India
&
\
verb
\
slshape India 
\
\
\
textsf{ India }
&
\
verb
\
textsf{ India }
&
\
sffamily
India
&
\
verb
\
sffamily India 
\
\
\
texttt{ India }
&
\
verb
\
texttt{ India }
&
\
ttfamily India
&
\
verb
\
ttfamily India 
\
\
\
end{tabular}
\
end{document}
14. Different available line spacing in Tex
14spaces.tex
\
documentclass {article}
\
begin {document}
\
section{Word Spacing}
MathematicsPhysics
\
\
Mathematics Physics
\
\
Mathematics
\
, Physics
\
\
Mathematics ~ Physics
\
\
Mathematics
\
quad{} Physics
\
\
Mathematics
\
qquad{} Physics
\
\
\
section{Horizontal Spaces}
Mathematics
\
hspace{2cm}Physics
\
\
Mathematics
\
hspace{2mm}Physics
\
\
Mathematics
\
hspace{10pt}Physics
\
\
Mathematics
\
hspace{

5cm}Physics
\
\
Mathematics
\
hfill Physics
\
subsection{Vertical}
Mathematics
\
vspace{2c
m}Physics
\
\
Mathematics
\
vspace{2mm}Physics
\
\
Mathematics
\
vspace{10pt}Physics
\
\
Mathematics
\
vspace{

5cm}Physics
\
\
Mathematics
\
vfill Physics
\
end{document}
15. Typesetting a sample Mathematical Question Paper
15mathqp.tex
\
documentclass[a4paper,11pt]{article}
\
usepackage{amsmath,amssymb}
\
usepackage[left=2cm,right=2cm,top=1.5cm,bottom=1.5cm]{geometry}
\
addtolength{
\
topmargin}{2.5mm}
\
renewcommand{
\
baselinestretch}{1.1}
\
newcommand{
\
score}[1]{
\
hfill($#1$~marks)}
\
newco
mmand{
\
me}{
\
mathrm e}
\
newcommand{
\
mi}{
\
mathrm i}
\
newcommand{
\
partialder}[2]{
\
frac{
\
partial^#1}{
\
partial #2^#1}}
\
newcommand{
\
partialderz}[2]{
\
frac{
\
partial^#1 z}{
\
partial #2^#1}}
\
pagestyle{empty}
\
renewcommand{
\
baselinestretch}{1.1}
\
begin{documen
t}
\
begin{center}
\
textsc{
\
Large College of Engineering, Perumon}
\
smallskip
\
large First Series Test

February~2011
\
smallskip
\
normalsize
CS/IT/EE/EC

401

\
textbf{Engineering Mathematics
\
,

\
,III}
\
end{center}
\
noindent Time~:~
\
textit{2} hours
\
hfill Max. Marks~:~
\
textit{50}
\
noindent
\
rule[10pt]{
\
textwidth}{0.9pt}
\
begin{center}
\
textbf{
\
large Part A}
(
\
itshape Answer all questions. Each question carries 5 marks)
\
end{center}
\
begin{enumerate}
\
item Using Cauchy

Riemann equations, show that $f(z)=z^3$ is analytic in the
entire $z$

plane and find its derivative.
\
item Prove that
$
\
log(1+r
\
me^{
\
mi
\
theta})=
\
frac{1}{2}
\
log
\
bigl(1+2r
\
cos
\
theta+r^2
\
bigr)+
\
mi
\
tan
^{

1}
\
frac{r
\
si
n
\
theta}{1+r
\
cos
\
theta}$
\
item
\
begin{enumerate}
\
item Form the pde by eliminating the arbitrary function $
\
phi$ from the
relation
\
\
$
\
phi(x^2+y^2+z^2,x+y+z)=0$.
\
score{2
\
frac{1}{2}}
\
item Form the pde representing the fa
mily of surfaces
$z=f
\
left(
\
frac{xy}{z}
\
right)$ by eliminating the arbitrary function
$f$.
\
score{2
\
frac{1}{2}}
\
end{enumerate}
\
item
\
begin{enumerate}
\
item Find the general integral of the pde
\
quad $px^2(y^3

z^3)+q y^2(z^3

x^3)=z^2(x^3

y^3)$.
\
score{3}
\
item If $(x

a)^2+(y

b)^2+z^2=1$ is a complete integral of the pde
$z^2(1+p^2+q^2)=1$, evaluate its singular
integral.
\
score{2}
\
end{enumerate}
\
end{enumerate}
\
begin{center}
\
textbf{
\
large Part B}
\
\
(
\
itshape Each question carries 15 marks)
\
end{center}
\
begin{enumerate}
\
item
\
begin{enumerate}
\
item If $f(z)$ is a regular function of $z$, prove that
$
\
displaystyle
\
left(
\
partialder{2}{x}+
\
partialder{2}{y}
\
right)f(z)
^2=4f'(z)^2
$
\
score{5}
\
item If $
\
mi^{
\
alpha+
\
mi
\
beta}=
\
alpha+
\
mi
\
beta$, prove that
$
\
alpha^2+
\
beta^2=
\
me^{

\
frac{(4n+1)
\
pi}{2}}$
\
score{5}
\
item Considering only the principal value, prove that the real part of
$(1+
\
mi
\
sqrt{3})^{1+
\
mi
\
sqrt{3}}$ is
\
\
$
\
displaystyle2
\
me^{

\
frac{
\
pi}{
\
sqrt{3}}}
\
cos
\
left(
\
frac{
\
pi}{3}+
\
sqrt{3}
\
log 2
\
right)$
\
score{5}
\
end{enumera
te}
\
smallskip
\
centerline{
\
bfseries OR}
\
smallskip
\
item
\
begin{enumerate}
\
item If $u

v=(x

y)(x^2+4xy+y^2)$ and $f(z)=u+
\
mi v$ is an analytic
function of $z=x+
\
mi y$, find $f(z)$ in terms of $z$.
\
score{7}
\
item Disc
uss the mapping defined by $w=
\
me^z$ and find the image of $

1<x<1$ under $w=
\
me^z$.
\
score{8}
\
end{enumerate}
\
item
\
begin{enumerate}
\
item Solve $p^2q^2+x^2y^2=x^2q^2(x^2+y^2)$.
\
score{6}
\
item Find a complete integral of $pqz=p+q$.
\
score{5}
\
item Show that $pqz=p^2(xq+p^2)+q^2(yp+q^2)$ is a Clairaut's equation.
Hence find a complete integral of
the equation.
\
score{4}
\
end{enumerate}
\
small
skip
\
centerline{
\
bfseries OR}
\
smallskip
\
item
\
begin{enumerate}
\
item Solve the pde $
\
partialder{3}{x}

2
\
frac{
\
partial^3 z}{
\
partial
x^2
\
,
\
partial y}

\
frac{
\
partial^3 z}{
\
partial x
\
,
\
partial
y^2}+2
\
partialderz{3}{y}=
\
me^{x+y
}$
\
score{8}
\
item Solve $r

s+2q

z=x^2y^2$
\
score{7}
\
end{enumerate}
\
end{enumerate}
\
end{document}
PART

II
PYTHON PROGRAMMING
1. Use of python as a calculator to compute simple interest
$ python3
>>>
p=50000
>>> r=9
>>> n=5
>>> p
50000
>>> r
9
>>> n
5
>>> si=p*n*r/100
>>> si
22500
2. Use of python as a calculator for temperature conversion
$ python3
# To convert 12
0
C to equivalent Faranheit scale
>>> c=12
>>> f=(c+9/5)+32
>>> f
53
#
To convert 41
0
Faranheit to equivalent
0
C scale
>>> f=41
>>> c=(f

32)*5/9
>>> c
5
# To convert 316K to equivalent
0
C scale
>>> k=316
>>> c=k

273
>>> c
43
# To convert 113
0
C to equivalent Kelvin scale
>>> c=113
>>> k=c+273
>>> k
336
3. Program
to compute the GCD of two given numbers
print()
a=int (input(‘Enter the first number a:’))
b=int (input(‘Enter the second number b:’))
while b!=0:
a, b=b, a%b
print(‘GCD of a and b is:’, a)
Output is:
$ python3 gcd.py
Enter the first number a: 21
Enter the second number b: 5
GCD of a and b is: 1
$ python3 gcd.py
Enter the first number a: 14
Enter the second number b: 9
GCD of a and b is: 1
$ python3 gcd.py
Enter the first number a: 26
Enter the second number b: 12
GCD of a and b is: 2
4. Program to check whether a given number is even or odd
print()
a=int (input(‘Enter the first number a:’))
if a%b = = 0:
print(‘given number is even’)
else:
print(‘given number is odd’)
Output is:
$ python3 evench.py
Enter the first number a:
21
given number is odd’
$ python3 evench.py
Enter the first number a: 18
given number is even’
$ python3 evench.py
Enter the first number a: 56
given number is even’
5.
Program to
check the primality of a given integer
print()
n=int
(input(‘Enter the given number, n:’))
for k in range(n):
if n% k= = 0:
print(‘The given integer’, n, ‘is not prime’)
status=’not prime’
break;
if status!=’not prime’:
print(‘The given integer’, n, ‘is prime’)
Output is:
$ py
thon3 primech.py
Enter the given number, n: 21
The given integer 21 is prime
$ python3 primech.py
Enter the given number, n: 56
The given integer 21 is not prime
$ python3 primech.py
Enter the given number, n: 31
The given integer 31 is prime
6.
Program to
list primes in a given range by SoE
print()
n=int (input(‘Enter the upper limit of the given range, n:’))
for a in range(2,n):
for k in range(2,a);
if a% k= = 0:
print(a, ‘is’, k, ‘*’, a/k)
else:
print(a, ‘is prime’)
Output is:
$ python3 primelist.py
Enter the upper limit of the given range, n: 7
2 is 2*1
3 is prime
4 is 2*2
5 is prime
6 is 2*3
7 is prime
$ python3 primelist.py
Enter the upper limit of the given range, n: 9
2 is 2*1
3
is prime
4 is 2*2
5 is prime
6 is 2*3
7 is prime
8 is 2*4
9 is prime
7.
Program to
generate the terms of Fibonacci sequence up to a given integer
print()
n=int(input(‘Enter a given integer, n:’))
a,b = 0,1
while a<n:
print(a)
a,b = b, a+b
Outpu
t is:
$ python3 fib.py
Enter a given integer, n: 50
0
1
1
2
3
5
8
13
21
34
$ python3 fib.py
Enter a given integer, n: 100
0
1
1
2
3
5
8
13
21
34
55
89
8.
Program to slice/append words by string operations
print()
s=’nsscollege’
print(s)
n=len(s)
print(‘The length of the string s is:’,n)
s=s[0:2]+’ ’+s[3:]
print()
s=s+’ ’
s=s+’cherthala’
print()
print(s[:3])
s=’mm’+’’+s[0:]
print(s)
Output is:
$ python3 string.py
nsscollege
The length of the string s is: 10
nss college
nss college cherthala
nss
mm nss college cherthala
9.
Program to reverse the digits of a given number
print()
s='1234567890'
print('The given number is:')
print(s)
n=len(s)
digits=[int(s[k]) for k in range(n)]
print('The digits of the given number are:')
first=digits
print(first)
digits.reverse()
print('reverse order of the digits of the given number is:')
print(digits)
sum=sum(first)
print('The sum of the digits of the number is:', sum)
Output is:
$ python3 reverse.py
The given number is:
12345678
90
The digits of the given number are:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
reverse order of the digits of the given number is:
[0, 9, 8, 7, 6, 5, 4, 3, 2, 1]
The sum of the digits of the number is: 45
10.
Program to
sort a list of numbers or names
print()
print('The list of given numbers is:')
s=[31,27,13,24,15,26,17,18,9,10]
print(s)
s.sort()
print('sorted order of the list is:')
print(s)
print('The list of given names is:')
s=['rsp','vk','tns','tss','npk','rk','js','dv','vv','jj']
print(s)
s.sort()
print('sorted order of the list is:')
print(s)
Output is:
$ python3 sort.py
The list of given number is:
31,27,13,24,15,26,17,18,9,10
sorted order of the list is:
31,27,13,24,15,26,17,18,9,10
The list of given names is:
['rsp', 'vk', 'tns', 'tss', 'npk', 'rk', 'js', 'dv', 'vv', 'jj']
sorted order of the list is:
['dv', 'jj', 'js', 'npk', 'rk', 'rsp', 'tns', 'tss', 'vk', 'vv']
11.
Program to
find the dot

product of vectors
print()
a=[1,2,3]
print('The first vector is:',
a)
b=[4,5,6]
print('The second vector is:',b)
d=0
for k in range(3):
d=d+a[k]*b[k]
print('The dot

product of a and b is:', d)
Output is:
$ python3 dot.py
The first vector is: [1, 2, 3]
The second vector is: [4, 5, 6]
The dot

product of a and b is: 32
12.
Program to
find the norm of partition of an interval
print()
import math
print('Enter the given partition of the interval as an array:')
p=[0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
print('The given partition is:')
print(p)
n=len(p)
print('The lengths of various subintervals are:')
s=[(p[k]

p[k

1]) for k in range(n)]
print(s)
norm=max(s)
print('The norm of the given partition is:')
print(norm)
Output is:
Enter the given partition of the interval as an array:
The give
n partition is:
[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
The lengths of various subintervals are:
[

1.0, 0.1, 0.1, 0.09999999999999998, 0.10000000000000003,
0.09999999999999998, 0.09999999999999998, 0.09999999999999998,
0.10000000000000009, 0.09999999999999998, 0.09999999999999998]
The norm of the given partition is:
0.10000000000000009
13.
Program
to
solve an equation by Bisection method
14.
Program to
solve by Regula

Falsi method
15.
Program to
solve by Newton

Raphson method
16.
Program to
evaluate integral by Trapezoidal rule
17.
Program to
evaluate integral by Simpson’s 1/3 rule
18.
Program
to
evaluate integral by Simpson’s 3/8 rule
19.
Program to
solve first order ODE by Euler method
20.
Program to
solve first order ODE by Runge

Kutta method
Enter the password to open this PDF file:
File name:

File size:

Title:

Author:

Subject:

Keywords:

Creation Date:

Modification Date:

Creator:

PDF Producer:

PDF Version:

Page Count:

Preparing document for printing…
0%
Comments 0
Log in to post a comment