PDS Ketan

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

PDS (3150713)

PRACTICAL 1
AIM: Implement program of “HelloWorld” in Python language.

CODE:

print ("Hello World")

OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 1
PDS (3150713)

PRACTICAL 2
AIM: Implement program of Primary Data Types (String, Integer, Float,
Complex, Boolean) in Python.

 String:
CODE:
#string
>>> str1="malek Azba"
>>> print(str1);
OUTPUT:

 Integer:
CODE:
#Integer
a=12
>>> print(a)
OUTPUT:

 Float:
CODE:
#Float
>>> z=34.55
>>> print(z)
OUTPUT:

 Complex:
CODE:
#Complex
>>> x=complex(4,9)
>>> print(x)

VIEAT/BE/SEM-5/220940107005 Page 2
PDS (3150713)

OUTPUT:

 Boolean:
CODE:
#Boolean
>>> p=90
>>> bool(p)
True
>>> q=100
>>> bool(q)
True
>>> bool(p==q)
OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 3
PDS (3150713)

PRACTICAL 3
AIM: Implement below program of using input function in Python.

 Write program to perform addition of two numbers.

CODE:
# Addiiton of Two numbers using input function
number1 = int(input ("Ener the value of first number for addition : "))
Ener the value of first number for addition : 78
number2 = int(input ("Enter the value of second number for addition : "))
Enter the value of second number for addition : 23
Addition=number1 + number2
print(Addition)
101
OUTPUT:

 Write a program to find square root of any number.

CODE:
# SquareRoot
num=int(input("Enter a number to find its SquareRoot : "))
Enter a number to find its SquareRoot : 25
result=num**0.5
print("Square root of " ,num, "is", result)
Square root of 25 is 5.0
OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 4
PDS (3150713)

PRACTICAL 4
AIM: Implement a conditional statements in Python.

CODE FOR LOOP & IF ELSE CONDITIONAL STATMENT:


#list of numbers
list_of_numbers=[2,4,6,9,5]
#for loop
for i in list_of_numbers:
if i % 2 != 0:
print(i, "is an odd number")
if i % 2 == 0:
print(i, "is an even number")
print(list_of_numbers)

# if else
for i in list_of_numbers:
if 1%2!=0:
print(i,"is an odd number")
else:
print(i,"is an even number")

OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 5
PDS (3150713)

PRACTICAL 5
AIM: Implement “for loop” & “while loop” in Python.

CODE FOR LOOP :


#list of numbers
list_of_numbers=[2,4,6,9,5]
#for loop
for i in list_of_numbers:
if i % 2 != 0:
print(i, "is an odd number")
if i % 2 == 0:
print(i, "is an even number")
print(list_of_numbers)

OUTPUT:

CODE WHILE LOOP :


#WHILE LOOP
i=1
n=7
while i<= n:
print(i,"Elements are")
i=i+1

OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 6
PDS (3150713)

PRACTICAL 6
AIM: Implement the user defined function to find factorial of any number.

CODE :
import math
num=5
factorial=math.factorial(num)
print("The factorial of",num,"is",factorial)

OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 7
PDS (3150713)

PRACTICAL 7
AIM: Implement the function to find area of Geometrical shapes (Square,
Rectangle, Circle & Triangle).

CODE FOR SQUARE:


Enter the side:5
area=side*side
print("Area of Square is:",area)
Area of Square is: 25

OUTPUT:

CODE FOR RECTANGLE:


s=int(input("Enter the side:"))
Enter the side:6
Area=s*s
Perimeter=4*s
print("Are of rectangle:",Area)
Are of rectangle: 36
print("Area of Rectangle:",Area)
Area of Rectangle: 36

OUTPUT:

CODE FOR CIRCLE:


r=float(input("Enter the radius of circle:"))
Enter the radius of circle:12
area=3.14*r*r
print("Area of Circle:",area)
Area of Circle: 452.15999999999997

OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 8
PDS (3150713)

CODE FOR TRIANGLE:


base=float(input("please enter the base of a triangle:"))
please enter the base of a triangle:15
height=float(input("please enter the height of a triangle:"))
please enter the height of a triangle:35
area=(base*height)/2
print("The area of a Triangle using ", base, "and",height,"=",area)
The area of a Triangle using 15.0 and 35.0 = 262.5

OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 9
PDS (3150713)

PRACTICAL 8
AIM: Implement Data Structures (List, Dictionary, Tuple, Set) in Python.

CODE FOR LIST:


my_list=[1,2,3,'python',3.3]
print(my_list)
[1, 2, 3, 'python', 3.3]
my_dict={1:'python',2:'java'}
print(my_dict)
{1: 'python', 2: 'java'}
my_tuple=(1,2,3)
print(my_tuple)
(1, 2, 3)
my_set={1,2,3,4,5}
print(my_set)
{1, 2, 3, 4, 5}

OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 10
PDS (3150713)

PRACTICAL 9
AIM: Implement the Program which perform of perform basic data
manipulations(delete empty,rows,columns,remove outliners)in .csv file
using Pandas on jupyter Notebook in python.
CODE:
# import module
import pandas as pd
# assign dataset
df = pd.read_csv("country_code.csv")
# display
print("Type-", type(df))
df
df.head(10)
df.shape
df1 = pd.read_csv("country_code.csv")
merged_col = pd.merge(df, df1, on='Name')
merged_col
OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 11
PDS (3150713)

PRACTICAL 10
AIM:Implement the program to perform in following
1.basic Numpy operation:-Create one,two,multi-dimensional Array.
2.Perform addition,Subtraction,multiplication and division operation on
two matrix.
3.Perform below functions of nump:-range(), arrange(), linespace(),
reshape() , zeroes(),ones(),min(),max(),sum(),sqrt() functions in Python.
1.basic Numpy operation:-Create one,two,multi-dimensional Array.
CODE:
import numpy as np
#creating one dimention array
print("creating one dimention array")
arr = np.array([10,28,35,32,11,37])
print(type(arr))
print(arr.shape)
print(arr.ndim)
#creating two dimention array
print("creating two dimention array")
arr2 = np.array([[10,20,30],[40,50,60]])
print(arr2)
print(arr2.ndim)
#creating multi dimention array
arr3 = np.array([[[1,2,3],[5,6,7]],[[10,20,30],[40,50,60]]])
print(arr3)
print(arr3.ndim)
OUTPUT:

2. Perform addition,Subtraction,multiplication and division operation on


two matrix.
CODE:
import numpy
x = numpy.array([[4, 6], [5, 2]])
y = numpy.array([[2, 5], [29, 1]])
print ("The element wise addition of matrix is : ")

VIEAT/BE/SEM-5/220940107005 Page 12
PDS (3150713)

print (numpy.add(x,y))
print ("The element wise subtraction of matrix is : ")
print (numpy.subtract(x,y))
print ("The element wise division of matrix is : ")
print (numpy.divide(x,y))
print ("The element wise multiplication of matrix is : ")
print (numpy.multiply(x,y))
print ("The product of matrices is : ")
print (numpy.dot(x,y))

OUTPUT:

3. Perform below functions of nump:-range(), arrange(), linespace(),


reshape() , zeroes(),ones(),min(),max(),sum(),sqrt() functions in Python.
CODE:
elements spaced out over a specified interval.
arr = np.arange(10)
print(arr)
and end.
np.linspace(5,25)
np.logspace(5,20)\
arr = np.array([10,2,3,5,22,77,2])
print(arr)
print(arr.max())
print(arr.min())
print(arr.sum())
OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 13
PDS (3150713)

VIEAT/BE/SEM-5/220940107005 Page 14
PDS (3150713)

PRACTICAL 11
AIM:Implement data visualization on .csv file by the use of matplotlib in
Python.
CODE:
import matplotlib.pyplot as plt
import csv
x = []
y = []
with open('biostats.csv','r') as csvfile:
plots = csv.reader("csvfile,delimiter "= ',')
for row in plots:
x.append(row[0])
y.append(int(row[2]))
plt.bar(x, y, color = 'g', width = 0.72, label = "Age")
plt.xlabel('Names')
plt.ylabel('Ages')
plt.title('Ages of different persons')
plt.legend()
plt.show()

OUTPUT:

VIEAT/BE/SEM-5/220940107005 Page 15

You might also like