Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Then just click Install Now. That should be all there is to it. A few minutes later a working
Python 3 will be installed on the system.
LAB 2
Objective: Control structures and Functions.
1. If else
# Program checks if the number is positive or negative and displays an appropriate
message
num = 3
if num >= 0:
print("Positive or Zero")
else:
print("Negative number")
2. While
# Program to add natural numbers upto sum = 1+2+3+...+n
n = int(input("Enter n: "))
n = 10
sum = 0
i=1
while i <= n:
sum = sum + i
i = i+1
print("The sum is", sum)
Output: Enter n: 10
The sum is 55
3. For loop
# Program to find the sum of all numbers stored in a list
4. Function
# Program to implement binary search
Output: False
True
LAB 3
Objective: Quick sort using recursion
#Program to implement Quick Sort
def quickSort(alist):
quickSortHelper(alist,0,len(alist)-1)
def quickSortHelper(alist,first,last):
if first<last:
splitpoint = partition(alist,first,last)
quickSortHelper(alist,first,splitpoint-1)
quickSortHelper(alist,splitpoint+1,last)
def partition(alist,first,last):
pivotvalue = alist[first]
leftmark = first+1
rightmark = last
done = False
temp = alist[first]
alist[first] = alist[rightmark]
alist[rightmark] = temp
return rightmark
alist = [54,26,93,17,77,31,44,55,20]
quickSort(alist)
print(alist)
Output: [17, 20, 26, 31, 44, 54, 55, 77, 93]
LAB 4
Objective: Control structures and Functions.
#Program to print roman values of the given decimal number.
class py_solution:
def int_to_Roman(self, num):
val = [
1000, 900, 500, 400,
100, 90, 50, 40,
10, 9, 5, 4,
1
]
syb = [
"M", "CM", "D", "CD",
"C", "XC", "L", "XL",
"X", "IX", "V", "IV",
"I"
]
roman_num = ''
i=0
print(py_solution().int_to_Roman(1))
print(py_solution().int_to_Roman(4000))
Output: I
MMMM
LAB 5
Objective: Object Orientation
class Person:
def say_hi(self):
print('Hello, how are you?')
p = Person()
p.say_hi()
# The previous 2 lines can also be written as
# Person().say_hi()
import tkinter
top = tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()
Output:
LAB 6
Objective: Installing LaTex
Step 1 – Go to miktex.org
Step 2 – Open download section
Step 3 – Download MiKTeX
\documentclass{article}
\begin{document}
My first \TeX~document.
\end{document}
Now please go to the command line and execute the following command.
latex test.tex
You should obtain the test.dvi file. This file can be seen in any DVI Viewer contained in the
TeX distribution, such as WinDVI, YAP and should look like what is shown below.
LAB 9 and 10
Objective: Concept of inserting table, arrays, contents, references in a
research paper using LaTex.
1. Table:
\documentclass{article}
\begin{document}
\begin{table}[h!]
\begin{center}
\caption{Your first table.}
\label{tab:table1}
\begin{tabular}{l|c|r} % <-- Alignments: 1st column left, 2nd middle and 3rd
right, with vertical lines in between
\textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
$\alpha$ & $\beta$ & $\gamma$ \\
\hline
1 & 1110.1 & a\\
2 & 10.1 & b\\
3 & 23.113231 & c\\
\end{tabular}
\end{center}
\end{table}
\end{document}
Ouput:
2. Array:
\begin{array}{lcl}
z & = & a \\
& = & a \\
f(x,y,z) & = & x + y + z
\end{array}
Ouput:
z =a
=a
f(x,y,z) = x+y+z
3. References:
documentclass{article}
\begin{document}
Random citation \cite{DUMMY:1} embeddeed in text.
\newpage
\bibliography{lesson7a1}
\bibliographystyle{ieeetr}
\end{document}
Output:
4. Table of contents:
\begin{document}
\begin{figure}
\caption{Dummy figure}
\end{figure}
\begin{table}
\caption{Dummy table}
\end{table}
\begin{appendix}
\listoffigures
\listoftables
\end{appendix}
\end{document}
Output: Compile two times