Practical:-1: Implement The Program of " Hello World " in Python Language
Practical:-1: Implement The Program of " Hello World " in Python Language
PRACTICAL :- 1
AIM :- Implement the program of “ hello world ” in python language .
CODE :
print("Hello world")
OUTPUT :
1
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
PRACTICAL – 2 :
AIM :- Implement program of primary data types (strings , integer ,float ,
complex, Boolean) in python.
SORCE CODE :
#STRING
print("NAME : kashish")
#INTEGER
num1 = int(45)
print("INTEGER VALUE :",num1)
#FLOAT
num2 = float(45.67)
print("FLOAT VALUE :",num2)
#COMPLEX
num3 = complex(2, -3)
print("COMPLEX VALUE :",num3)
#BOOLEAN
a=14
b=26
print(a==b)
OUTPUT :
2
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
PRACTICAL – 3:
AIM :- Implement below program using input function in python.
1) Write python program to perform addition of two numbers.
2) Write a python program to find square root of any number.
SOURCE CODE :
1)
#addtion
x = input("Type a number: ")
y = input("Type another number: ")
sum = int(x) + int(y)
print("The sum is: ", sum)
OUTPUT :
2)
#square root
import math
print (math.sqrt(65))
print (math.sqrt(85))
OUTPUT :
3
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
PRACTICAL – 4:
AIM :- Implement conditional statements in python.
SOURCE CODE :
If….Else statement
x= 56
y = 51
if x > y:
print ("x is greater than y")
elif x < y:
print("x is less than y")
OUTPUT :
4
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
PRACTICAL – 5 :
AIM :- Implement “for loop” and “while loop” in python.
SOURCE CODE:
#For loop
n =3
for i in range(1,11):
print (n,'x',i,'=',n*i)
#While loop
#MULTIPLICATION TABLE
n=22
i=1
while i<=10:
print(n,"x",i,"=",n*i)
i=i+1
OUTPUT:
5
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
PRACTICAL – 6 :
AIM :- Implement user define function to find factorial of any number.
SOURCE CODE:
import math
def fact(n):
return(math.factorial(n))
OUTPUT :
6
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
PRACTICAL – 7 :
AIM :- Implement the function to find the area of geometric shapes (square,
rectangle, circle, triangle)
SOURCE CODE:
#AREA OF SQUARE
print ("Enter the side of square :")
s =int(input())
a=s*s
print("\nArea of square= ",a)
#AREA OF RECTANGLE
l= int(input('Enter length of rectangle: '))
b= int(input('Enter breadth of rectangle: '))
area =l*b
print("Area of rectangle = ",area)
#AREA OF CIRCLE
r=int(input("Enter radius of circle : "))
g =2*3.14*r
print("Area of circle =",g)
#AREA OF TRIANGLE
x =int(input("Enter base of triangle : "))
y =int(input("Enter height of triangle : "))
z = 0.5*x*y
print("Area of traingle = ",z)
7
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
OUTPUT:
8
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
Practical:-8
Aim:- Implement Data Structures(List,Dictionary,Tuple,set) in Python.
List
Code:-
l = [3,6,5,2,10,1]
print(type(l))
print(l)
#adding new element in list
l.insert(3,10)
print(l)
#removing last element from list
l.pop()
print(l)
#sorting list
l.sort()
print(l)
Output:-
Dictionary
Code:-
profile= {"name" : "Jignasha","age" : 22,"roll_no":7040,"city":"Surat"}
print(type(profile))
print(profile)
#we can access eqandom element in dict
print("name is ",profile["name"])
print(profile["name"]," live in ", profile["city"])
9
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
Tuple
t= (65,20,50,9,52)
print(type(t))
print(t)
Output:-
Set
s = {40,"Jignasha","hello",10,22.68}
print(type(s))
print(s)
print(s)
Output:-
10
VIEAT/B.E./SEM-V/220943107040
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:-
11
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
12
VIEAT/B.E./SEM-V/220943107040
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:-
13
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
14
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
Output:-
15
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
16
VIEAT/B.E./SEM-V/220943107040
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()
17
VIEAT/B.E./SEM-V/220943107040
PDS(3150713)
Output:-
18
VIEAT/B.E./SEM-V/220943107040