Jasmine Practical File IP

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

Informatics

Practices
Jasmine Kaur Kohli
XII-D

PRACTICAL FILE 2022-2023


Area of rectangle

length=int(input(“Enter the length”))


breadth= int(input(“Enter the breadth”))
area=length*breadth
print(“The area of the rectangle is “,area)
Sum of two numbers

a=int(input(“Enter the first digit”))


b= int(input(“Enter the second digit”))
area=length*breadth
print(“The sum of the two digits is” ,a+b)
Vowel – not a vowel

x=input(“Enter an alphabet”)
if (x=='a' or x=='e' or x=='i' or x=='o' or x=='u'):
print("It is a vowel")
else:
print("Not a vowel")
Name and Age

name=(input("Enter your Name"))


age=(input("Enter your Age"))
print("Your name is", name, "and your age is", age, "years")
Good Morning “n” times

a=int(input("Enter a number"))
for n in range(0,a):
print("Good Morning")
Table of a number

a=int(input("Enter a number"))
for n in range(1,11):
print (n*a)
Sum of numbers till “n”

a=int(input("Enter the number"))


b=0
for i in range (1,a+1):
b=b+i
print(b)
Sum of even numbers from 1-10

sum=0
for n in range(1,11):
if n%2==0:
sum+=n
print(sum)
Sum of natural numbers from 1-5

sum=0
for n in range(1,6):
sum+=n
print(sum)
First 10 even numbers

for n in range(1,11):
print(n*2)
Odd/Even nos. up to a given no,

num=int(input("Enter a number"))
if num%2==0:
for n in range(2,num+1,2):
print(n)
elif num!=0:
for n in range(1, num+1,2):
print(n)
Greatest out of 3 numbers

a=int(input("Enter the first number"))


b=int(input("Enter the second number"))
c=int(input("Enter the third number"))
if a>b>c:
print(a, "is the largest number")
elif b>a and b>c:
print(b, "is the largest number")
else:
print(c, "is the largest number")
“N” multiples of a given no.

a=int(input("Enter a number"))
b=int(input("Enter how many times you need the multiple"))
for i in range(1,b+1):
print (i*a)
Square of “n” numbers

n=int(input("Enter a no"))
for n in range (0,n+1):
print(n**2)
Factorial

a=int(input("Enter the number"))


factorial=1
for n in range (1,a+1):
factorial=n*factorial
print(factorial)
Height Categorisation

height=h=int(input("Enter your height, in cm"))


if h<13:
print("Chid")
elif h>=13 and h<20:
print("Teenager")
else :
print("Adult")
Percentage in 5 Subjects

Maths=M=int(input("Enter your marks secured in Maths"))


English=E=int(input("Enter your marks secured in English"))
Physics=P=int(input("Enter your marks secured in Physics"))
Chemistry=C=int(input("Enter your marks secured in Chemistry"))
Infoprac=I=int(input("Enter your marks secured in IP"))
Average=(M+E+P+C+I)/400*100
print("Percentage secured is", Average)
Cost Price and Tax

cp=int(input("Enter the cost price of the bike"))


if cp>100000:
print("Tax to be payed is 15%")
elif cp>50000 and cp<=100000:
print("Tax to be payed is 10%")
elif cp<= 50000:
print("Tax to be payed is 5%")
Calculator with 4 operations

a=int(input("Enter the first digit"))


o=input("Enter the operation")
b=int(input("Enter the second digit"))
if o == "+":
print("The sum is", a+b)
elif o == "*":
print("The product is",a*b)
elif o == "/":
print("The quotient is", a/b)
elif o == "-":
print("The difference is",a-b)
else:
print("Enter +,-,/,* in operation")
Assigning Grades

p=int(input("Enter the percentage obtained"))


if p>90:
print("Grade A")
elif p>80 or p<=90:
print("Grade B")
elif p>=60 or p<=80:
print("Grade C")
elif p<60:
print("Grade D")
Leap year or not

y=int(input("Enter the year"))


if y%100==0:
if y%400==0:
print("Entered year is leap year")
else:
print("Entered year is not a leap year")
else:
if y%4==0:
print("Entered year is leap year")
else:
print("Entered year is not a leap year")
2 numbers are equal or not

num1=int(input("Enter the first number"))


num2=int(input("Enter the second number"))
if num1==num2:
print("Both the nummebrs are equal")
elif num1!=num2:
print("The numbers are not equal")
Number is a factor of the other

num1=int(input("Enter the first number"))


num2=int(input("Enter the second number"))
if num2%num1==0:
print(num1,"is a factor of",num2)
else :
print(num1,"is not a factor of",num2)
Number is a multiple of the other

num1=int(input("Enter the first number"))


num2=int(input("Enter the second number"))
if num1%num2==0:
print(num1,"is a multiple of",num2)
else :
print(num1,"is not a multiple of",num2)
If both numbers are even

num1=int(input("Enter the first number"))


num2=int(input("Enter the second number"))
if num1%2==0 and num2%2==0:
print("Both",num1,"and",num2,"are even")
else :
print("Both",num1,"and",num2,"are not even")
Odd/even out of both numbers

num1=int(input("Enter the first number"))


num2=int(input("Enter the second number"))
if num1%2==0:
print(num1,"is even")
elif num1!=0:
print(num1,"is odd")
if num2%2==0:
print(num2,"is even")
elif num2!=0:
print(num2,"is odd")
If both numbers are odd

num1=int(input("Enter the first number"))


num2=int(input("Enter the second number"))
if num1%2!=0 and num2%2!=0:
print("Both",num1,"and",num2,"are odd")
else :
print("Both",num1,"and",num2,"are not odd")
Sum is greater than product

num1=int(input("Enter the first number"))


num2=int(input("Enter the second number"))
s=num1+num2
p=num1*num2
if s>p :
print("The sum of the two numbers is greater than their product")
else:
print("The sum of the two numbers is lesser than their product")
Number is a multiple of 3/5

num1=int(input("Enter the first number"))


if num1%3==0 and num1%5==0:
print(num1,"is a multiple of both 3 and 5")
else :
print(num1,"is not a multiple of both 3 and 5")
Count of “The”

str1="He is playing in the ground. She is the only player. The playing condition is good."
a=(str1.count("the"))
b=(str1.count("The"))
print("Count of The/the in text:",a+b)
Average of 5 marks

M=int(input("Enter your marks secured in Maths"))


E=int(input("Enter your marks secured in English"))
P=int(input("Enter your marks secured in Physics"))
C=int(input("Enter your marks secured in Chemistry"))
IP=int(input("Enter your marks secured in IP"))
Average=(M+E+P+C+IP)/5
print("Average Marks are",Average)
Festival Name

Festival=['Lumbini','Mopin','Bihu','Chhath','Onam','Lohri','Pongal','Garba']
a=input("Enter the name of a festival")
print(a in Festival)
Simple Interest

principal=p=int(input("Enter the principal amount"))


time=t=int(input("Enter the time period in years"))
if t>12:
rate=r=10
print("Simple Interest is",(p*r*t)/100)
else :
rate=r=15
print("Simple Interest is",(p*r*t)/100)
Area and Circumference of Circle

pi=3.14
r=int(input("Enter the radius"))
area=a=pi*r**2
circumference=c=2*pi*r
print("The area of the circle is",a,"and the circumference is",c)
Series from List

Import pandas as pd
Jasmine","Rachneet","Satvik","Japjot","Sarnav","Nidhi"]
s1=pd.Series(l1,index=[10,20,30,40,50,60])
s1.name="Names"
s1.index.name="id"
print(s1.head(2))
print(s1.tail(2))
print(s1)
print(s1[2:4])
print(s1.values)
print(s1.size)
print(s1.empty)
print(s1.count())
Series from Dictionary

import pandas as pd
d1={"Jasmine":1,"Rachneet":2,"Satvik":3,"Japjot":4,"Sarnav":5,"Nidhi":6}
s1=pd.Series(d1)
s1.name="Names"
s1.index.name="S.no"
print(s1)
print(s1.head(3))
print(s1.tail(2))
print(s1[2:5])
print(s1.size)
print(s1.count())
print(s1.empty)
print(s1.values)
print(s1["Rachneet":"Japjot"])
print(s1.get(2))
Operations on Series

length=10
breadth=20
A=length*breadth
print(“Area of the rectangle is “,A)
DataFrame from series

import pandas as pd
l1=[78,95]
s1=pd.Series(l1)
l2=[89,67]
s2=pd.Series(l2)
l3=[95,84]
s3=pd.Series(l3)
df1=pd.DataFrame({"Term1":s1,"Term2":s2,"Term3":s3})
print(df1)
df1["final"]=df1["Term1"]/4+df1["Term2"]/4+df1["Term3"]/2
print(df1)
Vowels Series

Q) Create a series Vowels, having 5 elements with index labels ‘a’,‘e’, ‘i’, ‘o’ and ‘u’ and all the five
values set to zero. Check if it is an empty series.

Vowels=pd.Series(0,index=['a','e','i','o','u'])
print(Vowels)
print(Vowels.empty)
Series with alphabets

Q) Create a series EngAlph, having 5 elements with first 5 alphabets as values and default index
values.

import pandas as pd
l1=['a','b','c','d','e']
EngAlph=pd.Series(l1)
print(EngAlph)
Friends Series

Q) Create a Series; Friends, from a dictionary having roll numbers of five of your friends as data and
their first name as keys.

import pandas as pd
f1={"Jasmine":15,"Rachneet":25,"Madhav":17,"Satvik":21,"Anika":20}
Friends=pd.Series(f1)
print(Friends)
MT Series

Q) Create MTseries, an empty Series. Check if it is an empty series.

import pandas as pd
MTSeries=pd.Series()
print(MTSeries)
print(MTSeries.empty)
Dataframe from dictionary of lists

import pandas as pd
dict1={"n1":["Jasmine","Rachneet","Anika"],"a1":[16,15,17]}
df=pd.DataFrame(dict1)
df['Marks']=[35,34,21]
df.loc[4]=["Madhav",18,45]
print(df)
DataFrame from series

import pandas as pd
l1=[78,95]
s1=pd.Series(l1)
l2=[89,67]
s2=pd.Series(l2)
l3=[95,84]
s3=pd.Series(l3)
df1=pd.DataFrame({"Term1":s1,"Term2":s2,"Term3":s3})
print(df1)
df1["final"]=df1["Term1"]/4+df1["Term2"]/4+df1["Term3"]/2
print(df1)
DataFrame - Sales

Q) Create the following DataFrame Sales containing year wise sales figures for five sales persons in
INR. Use the years as column labels, and sales person names as row labels.

import pandas as pd
dict1={"2014":[100.5,150.8,200.9,30000,40000],"2015":[12000,18000,22000,30000,45000]}
Sales=pd.DataFrame((dict1),index=["Madhu","Kusum","Kinshuk","Ankit","Shruti"])
Sales["2016"]=[20000,50000,70000,100000,125000]
Sales["2017"]=[50000,60000,70000,80000,90000]
print(Sales)
print(Sales.index)
print(Sales.columns)
print(Sales.dtypes)
print(Sales.values)
print(Sales.shape)
print(Sales.size)
DataFrame – Sales (contd.)

import pandas as pd
dict1={"2014":[100.5,150.8,200.9,30000,40000],"2015":[12000,18000,22000,30000,45000]}
Sales=pd.DataFrame((dict1),index=["Madhu","Kusum","Kinshuk","Ankit","Shruti"])
Sales["2016"]=[20000,50000,70000,100000,125000]
Sales["2017"]=[50000,60000,70000,80000,90000]
print(Sales)
dict2={"2018":[160000,110000,500000,340000,900000]}
Sales2=pd.DataFrame((dict2),index=["Madhu","Kusum","Kinshuk","Ankit","Shruti"])
print(Sales2)
Sales=Sales.append(Sales2)
print(Sales)
print(Sales.T)
print(Sales.loc["Madhu","2017"])
print(Sales.loc["Madhu","2018"])
print(Sales.loc["Ankit","2017"])
print(Sales.loc["Ankit","2018"])
print(Sales.loc["Shruti","2016"])
Sales.loc["Sumeet"]=[196.2,37800,52000,78438,38852]
print(Sales)
Sales=Sales.drop(["2014"],axis=1)
print(Sales)
Sales=Sales.drop(["Kinshuk"],axis=0)
print(Sales)
Sales=Sales.rename ({'Ankit':'Vivaan','Madhu':'Shailesh'})
print(Sales)
Sales.loc["Shailesh","2018"]=10000
print(Sales)
DataFrame – Sales (contd.)
DataFrame – Sales (contd.)
DataFrame – Child

import pandas as pd
dict1={"Id":["001","002","003","004","005"],"Gender":["M","F","M","F","M"],
"Names":["Apple","Ball","Cat","Dog","Elephant"]}
Child=pd.DataFrame((dict1),index=["a","b","c","d","e"])
#print(Child)
Child["Age"]=[14,15,35,31,17]
#print(Child)
Child.loc["e"]=["006","F","Rachneet",82]
#print(Child)
Child.loc["d"]=["004","M","Dog",31]
print(Child)
print(Child.tail(4))
print(Child.head(2))
print(Child.index)
DataFrame – Members

import pandas as pd
dict1={"Name":["Mehak","Sarathi","Kamak"],
"Address":["Dwarka","Saket","PV"],
"Age":[22,35,38],
"Type":["Silver","Silver","Gold"],
"Fees":[1200,1000,1400]}
Members=pd.DataFrame((dict1),index=["M1","M2","M3"])
print(Members)
print(Members[["Name","Age"]] [Members["Type"]=="Gold"])
print(Members.loc["M2","Fees"] ,Members.loc["M3","Fees"])
Members.loc["M2","Address"]='Vasant Vihar'
print(Members)
Members["Fees"]=Members["Fees"]+100
print(Members)
DataFrame – Friends
import pandas as pd
dict1={'Name':["Alice","Charles","Alexander"],
'City':["Washington","Bangalore","Melbourne"],
"Age":[22,35,38],
'Country':["USA","Denmark","India"],
'Email_Id':["alice@gmail.com","null","abc@gmail.com"]}
Friends=pd.DataFrame(dict1,index=[1,2,3])
print(Friends)
print(Friends[["Name","Country"]])
print(Friends.loc[2,"Name"])
Friends.loc[4]=["Angel","New York",45,"Fance","angel@gmail.com"]
print(Friends)
Friends.loc[4,"Country"]="UK"
print(Friends)
Friends["Age"]=Friends["Age"]+10
print(Friends)
DataFrame – Details
Notebook
import pandas as pd
dict1 = {"Company": ["HCL", "HCL", "Asus"],
"Quantity":[32, 12, 46],
"Price":[18000, 14000, 15000]}
details = pd.DataFrame(dict1, index = ["Printer", "Scanner", "Monitor"])
#1st part
print(details["Price"]>15000)
#2nd part
print(details[["Quantity","Price"]])
#3rd part
print(details.loc["Printer":"Scanner"])
#4th part
df1 = details.drop("Printer", axis = 0)
print(details)
#5th part
details = details.drop("Company", axis = 1)
print(details)
To read a csv file

import pandas as pd
Details=pd.read_csv("C:/Users/jasmi/Desktop/PriceDetails.csv")
Table=pd.DataFrame(Details)
print(Table)
To convert DataFrame to csv

import pandas as pd
info={"Name":["Jasmine","Rachneet","Madhav","Satvik","Hridyanshu"],
"Age":[16,17,17,18,17],
"Class":["12-D","12-D","12-A","12-C","12-A"]}
Details=pd.DataFrame(info)
Details.to_csv(path_or_buf="C:/Users/jasmi/Desktop/Friends.csv")

CSV file gets saved on the designated


location

Created csv file:


Simple Line Graph

import matplotlib.pyplot as plt


x=[1,2,3,4]
y=[2,4,6,8]
plt.plot(x,y,color="purple")
plt.title("Line plot between x and y data")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()
Line Graph
Double Line(contd.)
Graph

import matplotlib.pyplot as plt


sub=["English","Chem","Bio","Phy"]
stud1=[80,95,70,74]
stud2=[85,92,75,98]
plt.plot(sub,stud1,label="Student 1",color="blue")
plt.plot(sub,stud2,label="Student 2",color="maroon")
plt.legend()
plt.title("Marks of 2 students")
plt.xlabel("Subject")
plt.ylabel("Marks")
plt.show()
Bar graph

import matplotlib.pyplot as plt


clas=["VII","VIII","IX","X"]
stud=[40,45,34,43]
plt.bar(clas,stud)
plt.xlabel("Class")
plt.ylabel("No of students")
plt.title("Graph")
plt.show()
Bar graph using data from csv file

import pandas as pd
import matplotlib.pyplot as plt
Friends=pd.read_csv("C:/Users\SRLAB\Desktop\Preboard_Jasmine.csv")
x=Friends["NAME"]
y=Friends["AGE"]
plt.bar(x,y,color="purple")
plt.xlabel("Name")
plt.ylabel("Age")
plt.title("Graph showing Name and Age of 3 Friends")
plt.show()
Histogram

import matplotlib.pyplot as plt


ht=[143,147,154,149,174,165,164,156,176,177,163,155,157,158,171,173]
plt.hist(ht,bins=[140,145,150,155,160,165,170,175,180],color="pink",edgecolor="black")
plt.xlabel("Height")
plt.ylabel("Number of people")
plt.title("Graph showing variation in height")
plt.show()
Database
Table - Scholars
Input Values in Scholar
Queries in Scholar
1. To display Name, Adm_No of those students who joined after year 2012

2. To display all the information of the student whose name is Amit

3. To add a record with the given details

4. To display all information of the students where semester is I

5. To display all information of the students where grade is C3


Queries in Scholar (contd.)
6. To display the FEE of Vijay

7. To Display all the information in descending order of Adm_No

8. To make ADM_NO as the primary key


Table - Transport
Input Values in Transport
Queries in Transport
1. Display RTno, Area_Covered and Charges for all the school buses

2. Display all the details from the above table in ascending order of Area_Covered

3. To remove the Column- Distance


Queries in Transport (contd.)
4. Increase the charges of Yadav Co. by 1000

5. Display the charges and area covered

6. Display the RTno and Area Covered for the routes where number of students is more than 100
Table - Flight
Input Values in Flight
Queries in Flight
1. Display details of all flights starting from Delhi

2. Display details of all flights that have more than 4 number of flights operating

3. Display flight codes, starting place, destination, number of flights


Queries in Flight (contd.)
4. Display destinations along with flight codes where destination is “Jaipur”

5. Display the flight code where number of stops is more than 2

6. Insert a new record in the table


Table - Gym
Input values in Gym
Queries in Gym
1. To display all information of the students of humanities in descending order of percentage

2. To add another column Bus_Fees with datatype and size as Decimal(8,2)


Table - Salesperson
Queries in Salesperson
1. Write SQL statements to, display names of salespersons and their salaries who have salaries in
the range 30000.00 to 40000.00

2. Write SQL statements to, display names of salespersons who have the word “Kumar” anywhere
in the name

3. Write SQL statements to increase the salary of all salesperson by 5000


Queries in Salesperson (contd.)
4. Give OUTPUT SELECT Name, SID FROM salesperson where area=”North”

5. Write SQL statements to, display names of salespersons where the name starts with “R”

6. Write SQL statements to display all different areas from the table
Table - Furniture

Q) Create the following table:


Queries in Furniture
1. To list the ITEMNAME which are priced at more than 15000 from the FURNITURE table.

2. To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before 22/01/2002
from the FURNITURE table in descending order of ITEMNAME.
Numeric Functions
1. Power Function

2. Rounding off Function

3. Mod Function
String Functions
1. Uppercase Function 4. Substring Function

2. Lowercase Function

3. Length Function
String Functions (contd.)
5. Left Function 8. Ltrim Function

6. Right Function 9. Rtrim Function

7. Instr Function 10. Trim Function


Date and Time Function
1. Now Function 5. Year Function

2. Date Function 6. Day Function

3. Month Function 7. Dayname Function

4. Monthname Function
Table - Product

Create the above table with appropriate data types and constraints.
Queries in Product
1. Delete the row with product name as shampoo

2. List the Product Code, Product name and price in descending order of their product name. If
PName is the same then display the data in ascending order of price.

3. To add a column Discount


Queries in Product (contd.)
4. Calculate the value of the discount in the table Product as 10 per cent of the UPrice for all those
products where the UPrice is more than 100, otherwise the discount will be 0.

5. Display the total number of products manufactured by each manufacturer.


Table - Streams
Q) Consider the following tables Student and Stream in the Streams_of_Students database. The
primary key of the Stream table is StCode (stream code) which is the foreign key in the Student
table. The primary key of the Student table is AdmNo (admission number).
Create the table Student by choosing appropriate data types based on the data given in the table.
Queries in Streams
1. Jay has now changed his stream to Humanities. Write an appropriate SQL query to reflect this.

2. Display the names of students whose names end with the character ‘a’. Also, arrange the
students in alphabetical order.

3. Display the names of students enrolled in Science and Humanities stream, ordered by student
name in alphabetical order, then by admission number in ascending order (for duplicating names).
Queries in Streams (contd.)
4. List the number of students in each stream having more than 1 student.

5. Display the names of students enrolled in different streams, where students are arranged in
descending order of admission number.

You might also like