sakthi_py_lab1[1]
sakthi_py_lab1[1]
PROGRAM:
temp=x
x=y
y=temp
OUTPUT 1:
Before Swapping :
After Swapping :
PROGRAM:
x,y=y,x
Output:
Before Swapping :
After Swapping :
Program :
import math
ans=math.sqrt(((x2-x1)**2)+((y2-y1)**2))
Output:
Enter x1 value :2
Enter x2 value :4
Enter y1 value :6
Enter y2 value :8
Program :
list1=[]
ele=int(input("Enter integer:"))
list1.append(ele)
ele=list1.pop(0)
list1.append(ele)
print(list1)
Output:
Enter integer:10
Enter integer:20
Enter integer:30
Enter integer:40
PROGRAM:
if (num % 2) == 0:
else:
Output 1:
Enter a number: 2
2 is Even number
Output 2:
Enter a number: 77
77 is Odd number
EXNO:2.2
PROGRAM:
if (a>b)and (a>c):
print(a,"is largest")
elif (b>c):
print(b,"is largest")
else:
print(c,"is largest")
Output:
3000 is largest
EX.NO: 2.3
Program:
total =m1+m2+m3+m4+m5
avg=(total/5)
print("Total :",total)
print("Average :",avg)
print("Pass")
print("2nd class")
print("1st class")
else:
else:
print("No Grade")
Output:
Total : 410
Average : 82.0
Pass
PROGRAM:
sum = 0
temp = num
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
else:
Output 1:
Output 2:
f=1
for i in range(1,n+1):
f=f*i
print(f)
Output 1:
Enter a Number :5
120
Output 2:
Enter a Number :7
5040
EXNO:2.6
PROGRAM:
print()
OUTPUT:
**
***
****
*****
******
EXNO:3.1
LINER SEARCH
Program :
if(array[i]==x):
return i
return -1
array=[6,9,12,11,24,99]
n=len(array)
result = linearSearch(array, n, x)
if(result == -1):
else:
Output :1
Output :2
BINARY SEARCH
Program :
low = 0
high = len(list1)-1
mid = 0
if list1[mid] < n:
low = mid + 1
high = mid-1
else:
return mid
return -1
list1 = [6,9,11,24,99,100]
result = binary_search(list1, n)
if result != -1:
else:
Output :2
Selection Sort
Program :
def selectionsort(array,size):
min_idx=step
for i in range(step+1,size):
if array[i]<array[min_idx]:
min_idx=i
(array[step],array[min_idx])=(array[min_idx],array[step])
data=[]
for i in range(0,p):
l=int(input())
data.append(l)
size=len(data)
selectionsort(data,size)
Number of elements: 6
24
11
29
After sorted list using selection sort: [7, 6, 9, 11, 24, 29]
EXNO:4.2
:Insertion Sort
Program:
def insertionsort(array):
key=array[step]
j=step-1
array[j+1]=array[j]
j=j-1
array[j+1]=key
data=[]
for i in range(0,p):
l=int(input())
data.append(l)
insertionsort(data)
Number of elements: 6
11
24
99
After sorted array using insertion sort : [1, 6, 9, 11, 24, 99]
EXNO:5.1
Merge Sort
Program :
def mergeSort(array):
if len(array) > 1:
r = len(array)//2
L = array[:r]
M = array[r:]
mergeSort(L)
mergeSort(M)
i=j=k=0
array[k] = L[i]
i += 1
else:
array[k] = M[j]
j += 1
k += 1
array[k] = L[i]
i += 1
k += 1
array[k] = M[j]
j += 1
k += 1
def printList(array):
for i in range(len(array)):
print()
if _name_ == '_main_':
array = []
for i in range(0,p):
l=int(input())
array.append(l)
mergeSort(array)
Output :
Number of elements: 6
24
11
99
Quick Sort
Program :
pivot = array[high]
i = low - 1
i=i+1
return i + 1
quickSort(array, low, pi - 1)
quickSort(array, pi + 1, high)
data=[]
for i in range(0,n):
l=int(input())
data.append(l)
quickSort(data, 0, n- 1)
Number of elements: 6
24
11
99
PROGRAM:
list1=[10,20,30,40,50]
list1.append(60)
list2=[100,200,300,400,500]
list2.reverse()
list3=[10,20,30,40,50]
list3.pop(1)
Output:
print()
a=[1,2,3,4,5,6,7,8,9,10]
print("list A ",a )
print("Index 0 to 3 :",a[0:4])
print("Index 3 to 5 :",a[3:6])
Output :
Index 0 to 3 : [1, 2, 3, 4]
Index 3 to 5 : [4, 5, 6]
a=(10,20,30,40,50,60)
print("Tuple is ",a)
highest=max(a)
low=min(a)
Output :
Highest value is 60
Lowest value is 10
EXNO:6.4
(a, b) = (b, a)
Output :
Enter value of A: 24
Enter value of B: 6
Value of B = 6
Value of B = 24
EX.NO: 7.1
print("To Display Sum Of Element , Add Element And Remove Element In The Set")
a={5,10,15,20,25,30}
sum_set=sum(a)
b={1,2,3,4,5}
b.add(6)
c={10,20,30,40,50}
c.remove(10)
Output:
To Display Sum Of Element , Add Element And Remove Element In The Set
a={1,2,3,4,5}
b={5,6,7,2,1}
Output:
A set is {1, 2, 3, 4, 5}
B set is {1, 2, 5, 6, 7}
print("Original Dictionary:")
print(Dictionary1)
Dictionary1.update(Dictionary2)
print(Dictionary1)
OUTPUT:
Original Dictionary:
Program :
def returnSum(myDict):
List=[]
for i in myDict:
list.append(myDict[I])
final=sum(list)
return final
def returnSum2(dict):
sum=0
for i in dict.values():
sum=sum+i
return sum
def returnSum3(dict):
sum=0
for i in dict:
sum=sum+dict[i]
return sum
print("Dictionary :",dict)
print("Calaulate The Area Of A Triangle Using\n With Argument With return type\n")
def area_triangle(h,b):
ans=(h*b)/2
return ans
ans=area_triangle(a,b)
Output :
Program :
def GCD_Loop( ):
if a > b:
temp = b
else:
temp = a
if (( a % i == 0) and (b % i == 0 )):
gcd = i
return gcd
num = GCD_Loop()
Output :
PROGRAM:
def factorial(n):
if n==0:
return 1
else:
return n*factorial(n-1)
num=int(input("Enter a number:"))
if num<0:
elif num==0:
else:
OUTPUT :
Enter a number:7
CONSONANTS IN A STRING
PROGRAM:
vowels=0
consonants=0
for i in str:
vowels=vowels+1;
else:
consonants=consonants+1;
OUTPUT:
PROGRAM:
string=input(("Enter a letter:"))
if(string==string[::-1]):
else:
OUTPUT:
Enter a letter:csc
Enter a letter:python
print("To Read N Name And Sort Name In Alphabetic Order Using String")
na=[]
for i in range(n):
na.append(a)
na.sort()
Output:
import numpy as np
arr1=np.arange(4,dtype=np.float_).reshape(2,2)
print('First array:')
print(arr1)
print("\nSecond array:")
arr2=np.array([12,12])
print(arr2)
print(np.add(arr1,arr2))
print(np.subtract(arr1,arr2))
print(np.multiply(arr1,arr2))
print(np.divide(arr1,arr2))
Output:
First array:
[[0. 1.]
[2. 3.]]
Second array:
[12 12]
[[12. 13.]
[14. 15.]]
[[-12. -11.]
[-10. -9.]]
[[ 0. 12.]
[24. 36.]]
[[0. 0.08333333]
[0.16666667 0.25 ]]
EX.NO:10.2
import pandas as pd
employees = pd.DataFrame({
'Statistician', 'Programmer'],
'2018-03-16'],
print("Employees Record")
print(employees)
print(employees)
print("\n Drop Column by Name \n")
print(employees)
print(employees)
employees.loc[employees.Occupation=='Programmer','Occupation']='S/W Engg'
print(employees)
employees.insert(3,"Country","US")
print(employees)
OUTPUT:
Employees Record
Program:
style.use('ggplot')
x=[5,8,10]
y=[12,16,6]
x2=[6,9,11]
y2=[6,15,7]
plt.plot(x,y,'b',label='line one',linewidth=6)
plt.plot(x2,y2,'r',label='line two',linewidth=9)
plt.title('Epic Info')
plt.ylabel('y axis')
plt.xlabel('x axis')
plt.legend()
plt.grid(True,color='k')
plt.show()
OUTPUT:
EX.NO:11.4
PROGRAM:
import numpy as np
panda= misc.face()
plt.imshow(panda)
plt.show()
flip_down = np.flipud(misc.face())
plt.imshow(flip_down)
plt.show()
OUTPUT:
EXNO:11.1
def program1():
f = open("python2.txt","w")
newline="\n"
f.write(para)
f.write(newline)
f.close()
def program2():
f = open("Javafile.txt","w")
newline="\n"
f.write(para)
f.write(newline)
f.close()
def program3():
data=f1.read()
data1=f2.read()
f3.write(data)
f3.write(data1)
f3.close()
program1()
print("Writing File1 Succussful")
program2()
program3()
Output:
Enter the para for pythonfile : Python is a general purpose programming language created by
Enter the para for Java file :Java also a progammin language created by Sun Microsystems .
Program :
def filecreation():
f = open("pythonfile.txt","w")
new_line="\n"
f.write(line)
f.write(new_line)
f.close()
def operation():
data=f1.read()
cnt_ucase =0
cnt_lcase=0
cnt_digits=0
for ch in data:
if ch.islower():
cnt_lcase+=1
if ch.isupper():
cnt_ucase+=1
if ch.isdigit():
cnt_digits+=1
filecreation()
operation()
Output :
try:
z=x/y
except ZeroDivisionError:
print("ZeroDivisionError Block")
else:
Output:1
Output:2
ZeroDivisionError Block
try:
if x>100 or x<0:
raise ValueError
except ValueError:
else:
if x>17:
else:
Output :1
Output:2
Output :3
try:
except TypeError:
print('Unsupported operation')
except ZeroDivisionError:
else:
try:
print (a/b)
except ValueError:
print('Unsupported operation')
except ZeroDivisionError:
Unsupported operation
EX.NO:13.1
class Student:
def getStudentInfo(self):
self.name=input("Name: ")
def PutStudent(self):
class Bsc(Student):
def GetBsc(self):
self.getStudentInfo()
def PutBsc(self):
self.PutStudent()
class Ba(Student):
def GetBa(self):
self.getStudentInfo()
self.PutStudent()
student1=Bsc()
student1.GetBsc()
student1.PutBsc()
student2=Ba()
student2.GetBa()
student2.PutBa()
OUTPUT:
Name: sakthi
Physics Marks: 87
Chemistry Marks: 67
Maths Marks: 66
Marks is Subjects 87 67 66
Name: siva
History Marks: 78
Geography Marks: 89
Economic Marks: 99
Marks is Subjects 78 89 99