Title | Python 4thupdate - fdher |
---|---|
Author | Dhinesh Ramachandran |
Course | Python Programming laboratory |
Institution | Anna University |
Pages | 22 |
File Size | 1.2 MB |
File Type | |
Total Downloads | 90 |
Total Views | 110 |
fdher...
P.R. ENGINEERING COLLEGE (AICTE Approved, Affiliated to Anna University. Chennai) (UGC Recognized Under 2(f) & 12(B)) (Accredited with ‘A’ Grade by NAAC) VALLAM, THANJAVUR - 613403
DEPARTMENT OF
MCA
RECORD NOTE
Name
:
Reg.No
:
Subject Code/Title :
MC4112 / Python Programming
Semester/Year
:
1st Semester / 1st Year
Department
:
Master of Computer Application
P.R. ENGINEERING COLLEGE (AICTE Approved, Affiliated to Anna University. Chennai) (UGC Recognized Under 2(f) & 12(B)) (Accredited with ‘A’ Grade by NAAC) VALLAM, THANJAVUR - 613403
MCA
DEPARTMENT OF
CERTIFICATE Certified that this is the bonofider record of practical work done in the MC4112 / Python Programming By Branch
Laboratory
Reg.No Master of Computer Application
During the Academic Year
Staff in Charge
Semester
1st Semester
2021 - 2022
Head of the Department
Submitted for the University Practical Examination held on
Internal Examiner
External Examiner
INDEX S.NO
CONTENT
1
Simple statements and Expressions: I. Exchange the values of two variables II. Circulate the values of n variables III. Distance between two points
2
Scientific problems using Conditionals and Iterative loops
3
Linear search and Binary search
4
Selection sort, Insertion sort
5
Merge sort, Quick Sort
6
Implementing applications using Sets, Dictionaries
7
Implementing programs using Functions
8
Implementing programs using Strings
9
Modules and Python Standard Libraries: I. Pandas II. Numpy III. Matplotlib IV. scipy
10
Implementing real-time/technical applications using File handling
11
Implementing real-time/technical applications using Exception handling
12
Implementing real-time/technical applications using Exception handling.
13
Creating and Instantiating classes
MARKS
PAGE NO SIGNATURE
EX NO : 01 Date :
Simple statements and expressions. (exchange the values of two variables, circulate the values of n variables, distance between two points)
1(a).Exchange the value of two variables. Aim: To exchange the given values of two variables using python.
Algorithm: Step 1: Start the program. Step 2: Declare the variables a, b and read the inputs. Step 3: Print a before swapping variable. Step 4: Declare third variable, c. Step 5: Set c=a, a=b, b=c. Step 6: Print the value of a and b. Step 7: Stop the program.
Program: print("Swapping using temporary variable") a = int(input("a = ")) b = int(input("b = ")) print("Before Swapping") print("a = ", a) print("b = ", b) c = a a = b b = c print("After Swapping") print("a = ", a) print("b = ", b)
Output:
1(a).Exchange the value of two variables
Result: Thus the python programs to swap two input numbers have been done successfully And the output is verified.
1(b).Circulate the values of n variables. Aim: To circulate the values of n variables using python.
Algorithm: Step 1: Start the program. Step 2: Declare a function circulate with two parameters. Step 3: Set the value of i to 1. Step 4: While the value of i is less than or equal to number of rotations, repeat the instructions in step 5 and step 6. Step 5: Declare a variable j to store a length of listt using len() function. Step 6: While the value of j is greater than 0, repeat the instruction in step 7 and step 8. Step 7: Declare a variable temp for storing listt value. Step 8: Print a rotation of i. Step 9: Set a value of listt. And stop the program.
Program: def circulate(listt, num_of_rotation): i = 1 while(i 0): temp = listt[j] listt[j] = listt[j-1] listt[j-1] = temp j = j-1 print("rotation", i, listt) i = i+1 return listt = [1, 2, 3, 4, 5] circulate(listt, 3)
Output:
1(b). Circulate the values of n variables
Result: Thus the python programs to circulate the value of n variable have been done successfully and the output is verified.
1(c).Distance between two points. Aim: To find a distance between two points using python.
Algorithm: Step 1: Start the program. Step 2: Take a two points as an input from a user. Step 3: Calculate the difference between the corresponding, X-coordinates i.e.: X2 - X1 Y-coordinates i.e.: Y2 - Y1 of two points. Step 4: Apply the formula derived from Pythagorean Theorem. √(𝒙𝟐 − 𝒙𝟏)𝟐 + (𝒚𝟐 − 𝒚𝟏)𝟐 Step 5: Print a value of distance. Step 6: Stop the program.
Program: import math x1 = int(input("enter x1 : ")) y1 = int(input("enter y1 : ")) x2 = int(input("enter x2 : ")) y2 = int(input("enter y2 : ")) distance = math.sqrt((x2-x1)**2)+((y2 - y1)**2) print(distance)
Output:
1(c). Distance between two points
Result: Thus the python programs to calculate distance between two points have been done successfully and the output is verified.
EX NO : 02 Scientific problems using Conditionals and Iterative loops Date :
2(a).Conditionals Aim: To develop a program for checking whether the given number is an even number (or) add numbers.
Algorithm: Step 1: Start the program. Step 2: Declare the variables num and read the input for using input function. Step 3: If num%2==0 then print the number is even. Step 4: Else print the number is add. Step 5: Stop the program.
Flowchart:
Condition
Code inside Else body
Condition
Code inside If body
Program: num = int(input("Enter a number :")) X = num if(num % 2) == 0: print("You are value is even", num) else: print("You are value is odd", num)
Output:
2(a). Conditionals
Result: Thus the python programs to find add or even using conditionals has been executed successfully.
2(a). Iterative loops Aim: To develop a program for calculate sum of series using python.
Algorithm: Step 1: Start the program. Step 2: Take a two points as an input from a user. Step 3: Initiate a variable s=0, i=0. Step 4: While the value of i is less than or equal to n, repeat the instructions in step 5 and step 6. Step 5: s=s+x**I and i=i+1. Step 6: Print a sum of series. Step 7: Stop the program.
Flowchart: Start
Body of loop
If condition is TRUE
Condition
If condition is FALSE Stop
Program: x = int(input("enter the value of x : ")) n = int(input("enter the value of n : ")) s = 0 i = 0 while(i arr[j]: prev = j arr[i], arr[prev] = arr[prev], arr[i] print("\nSorted list :") for i in range(len(arr)): print("%d" % arr[i], end=" ")
Output:
4(a). Selection sort
Result: Thus the python programs to sort an element in a list using selection sort has been executed successfully.
4(a).Insertion sort Aim: Write a program to sort an element in a list using insertion sort concept in python.
Algorithm: Step 1: Start the program. Step 2: Initialize the list. Step 3: Print a given list using loop. Step 4: Declare a function with one parameter. Step 5: Initiate a loop for i in range of 1 and length of list. Step 6: Declare a two variable. key = arr[i] j = i-j Step 7: While the value of j is greater than or equal to 0 and key less than arr[j] repeat the instructions arr[j + 1] = arr[j]. Step 8: Print a sorted list using loop. Step 9: Stop the program.
Program: def insertionSort(arr): for i in range(1, len(arr)): key = arr[i] j = i-1 while j >= 0 and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key arr = [12, 11, 13, 5, 6]
print("Given List :") for i in range(len(arr)): print("%d" % arr[i], end=" ") insertionSort(arr) print("\nSorted List :") for i in range(len(arr)): print("% d" % arr[i])
Output:
4(b). Insertion sort
Result: Thus the python programs to sort an element in a list using selection sort has been executed successfully....