Python Lab Practical
Python Lab Practical
Interactive mode
Script mode
Interactive Mode
Example :
Script Mode
You Write your code in a text file then save it with a .py extension which stand for
“Python”.
Example :
Output : -
2.Write a program to purposefully raise Indentation Error and Correct it
Example : Python Indentation Error
Output : -
Exercise 2 - Operations
We will use the distance formula derived from Pythagorean theorem. The
formula for distance between two point (x1, y1) and (x2, y2) is
Distance =
Example : -
Output : -
1.Write a program add.py that takes 2 numbers as command line
arguments and prints its sum.
Output : -
Exercise - 3 Control Flow
Output : -
# Number is 4 and it is even number
Output : -
1/2=0.5
1/3= 0.3333333333333
…
…..
1/10=
0.1
2. Write a program using a for loop that loops over a sequence.
Output : -
3. Write a program using a while loop that asks the user for a
number, and prints a countdown from that number to zero.
Output : -
Exercise 4 - Control Flow –
Continued
1. Find the sum of all the primes below two million. Adding the previous
two terms, each new term in the Fibonacci sequence is generated. By
starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55,
89, ...
Output : -
# Fibonacci sequence
Output : -
2. By considering the terms in the Fibonacci sequence whose values
do not exceed four million, find the sum of the even-valued terms.
Output :-
3.Linear search and Binary search
# Linear Search
Output : -
#Binary Search
Output : -
4. Selection sort, Insertion sort
# Selection sort
Output : -
# Insertion Sort
Output : -
Exercise - 5 – DS
1. Writea program to count the numbers of characters in the string
and store them in a dictionary data structure
Output : -
2:Write a program to use split and join methods in the string
and trace a birthday with a dictionary data structure.
output: