Ip Practical File PDF

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 34

INFORMATICS

PRACTICES
PRACTICAL FILE

AKSHAT AGARWAL

4323

ROLL NO. 4

pg. 1
PYTHON
Q.1 WRITE A PROGRAM THAT CALCULATES THE FOLLOWING:
. AREA OF A CIRCLE
.CIRCUMFERENCE OF A CIRCLE
.AREA OF RECTANGLE
.PERIMETER OF A RECTANGLE

PROGRAM:
while True:
print('1. for area of circle')
print('2. for area of rectangle')
print('3. for circumference of circle')
print('4. for area of square')
ch=int(input('enter your choice:enter 0 to exit'))
if ch==1:
r=int(input('enter the radius of the circle:'))
a=3.14*r*r
print('area of circle:',a)
elif ch==2:
l=int(input('enter the length:'))
b=int(input('enter the breath:'))
a=l*b
print('area of rectangle:',a)
elif ch==3:
r=int(input('enter the radius of the circle:'))
c=2*(int(3.14*r))
print('circumference of circle:',c)

pg. 2
elif ch==4:
l=int(input('enter the side of square:'))
a=l*l
print('area of square:',a)
elif ch==0:
break
else:
print('invalid option')
OUTPUT:

Q.2 WRITE A PROGRAM THAT READS A STRING AND DISPLAYS THE


LONGEST SUBSTRING OF THE GIVEN STRING.
PROGRAM:
str1=input('enter the string:')
word=str1.split()
maxlength=0
maxword=''
for i in word:
x=len(i)
if x>maxlength and i.isalpha()==True:
print(i)
maxlength=x

pg. 3
maxword=i
print('substring with maximum length is:',maxword)
OUTPUT:

Q.3 WRITE A PROGRAM T0 CHECK WHETHER THE STRING IS A


PALINDROME OR NOT.
PROGRAM:
str=input('enter the string:')
l=len(str)
p=l-l
index=0
while(index<p):
if(str[index]==str[p]):
index=index+1
p=p-1
else:
print('string is not a palindrome')
break
else:
print('string is a palinndrome')
OUTPUT:

pg. 4
Q.4 WRITE A PROGRAM TO STORE STUDENTS INFORMATION LIKE
ADMISSION NUMBER, ROLL NO. , NAME AND MARKS IN A
DICTIONARY AND DISPLAY INFORMATION ON THE BASIS OF
ADMISSION NO.
PROGRAM:
SCL=dict()
i=1
flag=0
n=int(input('enter number of entries:'))
while i<=n:
adm=input('\nenter admission no. of a student:')
nm=input('enter name of the student')
section=input('enter class and section:')
per=float(input('enter the percentage of a student'))
b=(nm,section,per)
SCL[adm]=b
l=SCL.keys()
for i in l:
print('\nadmno-',i,':')
z=SCL[i]
print('name\t','class\t','per\t')
for j in z:
print(j,end='\t')

pg. 5
OUTPUT:

Q.5 WRITE A PROGRAM TO FIND THE OCCURENCES OF EACH


LETTER PRESENT IN THE GIVEN STRING.
PROGRAM:
st1=input('please enter your own string:')
char=input('please enter your own chracter')
c=0
for i in range(len(st1)):
if(st1[i]==char):
c=c+1
print('total occurence of ',char,'is',c)
OUTPUT:

Q.6 WAP USING PYPLOT TO PLOT A LINE CHART TO DEPICT THE


CHANGING WEEKLY ONION PRICES FOR FOUR WEEKS.

pg. 6
PROGRAM:
import matplotlib.pyplot as plt
weeks=(1,2,3,4)
prices=(25,30,60,40)
plt.plot(weeks,prices,'r-.')
plt.xlabel('no. of weeks')
plt.ylabel('prices of onion')
plt.title('change in price of onion')
plt.show()

OUTPUT:

Q.7 First 10 terms of a Fibonacci series in a list namely fib:


fib=[0,1,1,2,3,5,8,13,21,34]

pg. 7
WAP to plot Fibonacci terms and their square roots with two separate lines on
the same plot.
· The Fibonacci series should be plotted as a cyan line with ‘o’ markers having
size as ‘5’ and edge-color as red
PROGRAM:
import matplotlib.pyplot as plt
fib=(0,1,1,2,3,5,8,13,21,34)
x=(1,2,3,4,5,6,7,8,9,10)
sq=(0,1,1,4,9,25,64,169,441,1156)
plt.plot(x,fib,color='cyan',marker='o',markersize=5,markeredgecolor="red",labe
l='fibonnaci series')
plt.plot(x,sq,color='black',marker='+',markersize=7,markeredgecolor="red",labe
l='its square')
plt.legend()
plt.xlabel('no. os series')
plt.ylabel('squares and series')

pg. 8
plt.title('ABC')plt.show()

Q.8 WAP TO PRESENT A LINE GRAPH WITH LINE RED AND DOTTED
TAKING
X=[1,2,3,4,5,6,7,8,9,10]
Y=[1,4,9,16,25,36,49,64,81,100]
PROGRAM:
import matplotlib.pyplot as plt
x=[1,2,3,4,5,6,7,8,9,10]
y=[1,4,9,16,25,36,49,64,81,100]
plt.plot(x,y,c="red",ls="dotted",lw=20)
plt.grid(True)
plt.xlabel("age group")

pg. 9
plt.ylabel("height")
plt.title("painting")
plt.show()

OUTPUT:

Q.9 Cosider the reference table given above and write a program to plat a bar
chart from the medals won by Australia.
PROGRAM:
import matplotlib.pyplot as plt
medals=('gold','silver','bronze')
x=(1,2,3)
y=(80,59,59)
plt.bar(x,y,color='red')
plt.xticks(x,medals)
plt.title('Medals won my australia')
plt.xlabel('medals categories')

pg. 10
plt.ylabel('no. of medals')
plt.show()

OUTPUT:

Q.10 Cosider the reference table given above and write a program to plat a bar
chart from the medals won by India. Make sure that the Gold, Silver, Bronze
and Total tally is represented through different colours.
PROGRAM:
import matplotlib.pyplot as plt
plt.xkcd()
x=(1)
y=(26)
x1=(2)
y1=(20)

pg. 11
x2=(3)
y2=(20)
x3=(4)
y3=(66)
plt.bar(x,y,color='red',label='gold')
plt.bar(x1,y1,color='yellow',label='silver')
plt.bar(x2,y2,color='green',label='broze')
plt.bar(x3,y3,color='blue',label='total')
plt.legend()
plt.title('Medals won my australia')
plt.xlabel('medals categories')
plt.ylabel('no. of medals')
plt.tight_layout()

pg. 12
plt.show()

OUTPUT:
Q.11 Cosider the reference table given above and write a program to plat a bar
chart from the medals won by top four countries. Make sure that bars are
separately visible.
PROGRAM:
import matplotlib.pyplot as plt
medals=('gold','silver','bronze')
x=(1,2,3)
y=(80,59,59)
x1=(1,2,3)
y1=(45,45,46)
x2=(1,2,3)
y2=(26,20,20)

pg. 13
x3=(1,2,3)
y3=(15,40,27)
plt.subplot(4,1,1)
plt.bar(x,y,color='red')
plt.title('AUSTRALIA')
plt.xticks(x,medals)
plt.subplot(4,1,2)
plt.bar(x1,y1,color='yellow')
plt.title('ENGLAND')
plt.xticks(x,medals)
plt.subplot(4,1,3)
plt.bar(x2,y2,color='blue')
plt.title('INDIA')
plt.xticks(x,medals)
plt.subplot(4,1,4)
plt.bar(x3,y3,color='green')
plt.title('CANADA')
plt.xlabel('medals categories')
plt.tight_layout()
plt.xticks(x,medals)
plt.show()
OUTPUT:

pg. 14
Q.12 WAP TO PLOT A BAR GRAPH WITH ORANGE IN COLOUR.
PROGRAM:
import matplotlib.pyplot as plt
x=[1,2,3,4,5,6,7,8,9,10]
y=[1,4,9,16,25,36,49,64,81,100]
plt.bar(x,y,color='orange')
plt.show()
OUTPUT:

pg. 15
Q.13 WAP that gathers height and weights of 100participants and recorded
participants ages as :
ages= [1,1,2,3,……………………..100 values](take any random values)
WAP to plot a histogram from above data with 20 bins.
PROGRAM:
import matplotlib.pyplot as plt
import numpy as np
ages=np.random.randn(100)

pg. 16
wieght=np.random.randn(100)
plt.hist(ages,bins=20,weights=wieght,edgecolor='red',facecolor='blue')
plt.xlabel('ages')
plt.ylabel('wieghts')
plt.title('wieghts of 100 students')
plt.show()
OUTPUT:

Q.14 WAP TO PLOT A HISTOGRAM OF RANDOM VALUES.


PROGRAM:
import matplotlib.pyplot as plt
import numpy as np
y=np.random.randn(1000)
plt.hist(y)

pg. 17
plt.show()
OUTPUT:

Q.15 WAP TO PLOT A HISTOGRAM WITH RANDOM VALUES WITH


BINS AS 25.
PROGRAM:
import matplotlib.pyplot as plt
import numpy as np
y=np.random.randn(1000)
plt.hist(y,25)
plt.show()
OUTPUT:

pg. 18
Q.16 WAP TO CREATE A SERIES AS S WITH INDEX AS [A,B,C,D] AND
VALUES AS [10,20,30,40].
PROGRAM:
import pandas as pd
s=pd.Series([10,20,30,40],index=['a','b','c','d'])
print(s)
OUTPUT:

Q.17 WAP TO CREATE SERIES USING ARANGE FUNCTION OF NP


ARRAY.

pg. 19
PROGRAM:
import pandas as pd
import numpy as np
s=pd.Series(np.arange(2,7))
print(s)
OUTPUT:

Q.18 WAP TO PERFORM ARTHEMETIC OPERATIONS ON SERIES .


PROGRAM:
import pandas as pd
s1=pd.Series([1,2,3,4,5])
s2=pd.Series([3,4,5,6,7])
s3=pd.Series([5,6,7,8,9])
r1=s1+s2
print('sum')
print(r1)
r2=s1-s2
print('difference')
print(r2)
r3=s1*s2
print('multiplication')
print(r3)
r4=s3/s2

pg. 20
print('divide')
print(r4)
r5=s1**2
print('power')
print(r5)
OUTPUT:

Q.19 WAP TO CHANGE THE DATATYPE OF A SERIES.


PROGRAM:
import pandas as pd
import numpy as np
o=np.arange(2020,2030,2)
s=pd.Series(200,index=o,dtype='float64')

pg. 21
print(s)
OUTPUT:

Q.20 WAP TO CREATE A SERIES USING DICTIONARY.


PROGRAM:
import pandas as pd
s={'jan':1,'feb':2,'march':3}
s1=pd.Series(s,dtype="float64")
print(s1)
OUTPUT:

Q.21 CREATE A DATAFRAME USING DICTIONARY.


PROGRAM:
import pandas as pd
yr1={'qtr1':44900,'qtr2':46100,'q3':57000,'q4':59000}
yr2={'a':54500,'b':51000,'qtr4':57000}
disales1={1:yr1,2:yr2}

pg. 22
df3=pd.DataFrame(disales1)
print(df3)

OUTPUT:

Q.23 WAP TO SHOW INDEXS AND AXES OF A DATAFRAME.


PROGRAM:
import pandas as pd
a=[24,64,45]
b=[23,72,82]
c=[7,9,10]
sd=[a,b,c]
s=pd.DataFrame(sd,index=['a','b','c'],columns=['d','e','f'])
print(s)
print('it represent index')
print(s.index)
print('it represnt axes')
print(s.axes)
OUTPUT:

pg. 23
Q.24 WAP TO REPRESENT SIZE AND SHAPE OF THE FOLLOWING
DATAFRAME.
PROGRAM:
import pandas as pd
a=[26,64,45]
b=[24,72,82]
c=[7,2,10]
sd=[a,b,c]
s=pd.DataFrame(sd,index=['Q','W','E'],columns=['R','T','Y'])
print(s)
print('it represent size')
print(s.size)
print('it represnet shape')
print(s.shape)

OUTPUT:

pg. 24
Q.25 WAP TO TRANSPOSE THE VALUES OF INDEX AND COLUMNS IN
A DATAFRAME:
PROGRAM:
import pandas as pd
a=[26,64,45]
b=[24,72,82]
c=[7,2,10]
sd=[a,b,c]
s=pd.DataFrame(sd,index=['Q','W','E'],columns=['R','T','Y'])
print(s.T)

OUTPUT:

pg. 25
SQL
Q.26-30 CREATE A TABLE EMP AND PERFORM VARIOUS FUNCTIONS
ON IT :-
A) DISPLAY ENAME WHOSE SALARY IS BETWEEN 30000,70000.
B) DISPLAY ALL DETAILS OF EMPLOYEES WHOSE STARTS WITH R.
C) DISPLAY ALL DETAILS OF THE EMPLOYEES HAVING SALARY
MORE THAN 40000 IN ASCENDING ORDER.
D) DISPLAY MINIMUM SALARY AND MAXIMUM SALARY OF
EMPLOYEES.
E) DISPLAY SUM OF SALARY IN TABLE EMP.

OUTPUT:

pg. 26
pg. 27
pg. 28
pg. 29
Q.31-35 WRITE ACODE TO MAKE A DOUBLE TABLE EMP AND DEPT
WITH 5 ROWS AND PERFORM VARIOUS PROGRAMS-:
31- SELECT EMPLOYEE NAME , ESAL, DEPARTMENT NAME WHERE
ESAL IS GREATER THAN EQUAL TO 20000.
32. SELECT EMPLOYEE NAME , SALARY, DEPARTMENT NAME,
WHERE DEPARTMENT NAME IS DELHI.
33. SELECT EMPID , DEPARTMENT SALARY, DEPARTMENT NAME .
34. COUNT OF DEPARTMENT WHERE DEPARTMENT SALARY IS
EQUAL TO MORE THAN 30000.
35. SELECT MAXIMUM, MINIMUM, AVERAGE EMPLOYEE SALARY .

OUTPUT:

pg. 30
pg. 31
pg. 32
pg. 33
pg. 34

You might also like