Khatauli , Muzaffarnagar
PRACTICAL FILE
Subject: INFORMATICS PRACTICES
Code: 065
Submitted By
_______________
Class : XI
Under the Guidance of
Mr. ARUN KUMAR
PGT -Computer
INDEX
S.No Contents Date Sign
1. To find average and grade for given marks.
2. To find amount for given cost-qty-discount.
3. To calculate cost perimeter-wise/ area-wise.
4. Program to calculate simple interest.
5. To calculate profit-loss for given Cost and Sell Price.
6. To calculate EMI for Amount, Period and Interest.
7. To calculate tax (examples from GST/Income Tax)
8. To find the largest and smallest numbers in a list.
9. To check the number is negative or positive.
10. To find the sum of squares of the first 100 natural numbers.
11. To find whether a string is a palindrome or not.
12. To compute xn, for given two integers x and n,
13. To compute the greatest common divisor of two integers.
14. To compute the least common multiple of two integers.
15. Import numpy as `np` and print the version number.
16. Program to convert a list of numeric value into a 1DNumPy array.
17. To create a numPy array with all values as True or False
18. To extract all odd numbers from numPy array.
19. To extract all even numbers from numPy array.
20. NumPy: Create an array with values ranging from 1 to 10.
21. NumPy program to reverse an array elements.
22. Program to create a 3x3 matrix with values ranging from 2 to 10.
23. Data Management : SQL commands
1. ..Program to find the average and grade for the given Marks.
sub1=int(input("Enter marks of the first subject: "))
sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5
print ”average is:”, avg
if(avg>=90):
print("Grade: A")
elif(avg>=80&avg<90):
print("Grade: B")
elif(avg>=70&avg<80):
print("Grade: C")
elif(avg>=60&avg<70):
print("Grade: D")
else:
print("Grade: F")
OUTPUT:
Enter marks of the first subject: 95
Enter marks of the second subject: 95
Enter marks of the third subject: 90
Enter marks of the fourth subject: 90
Enter marks of the fifth subject: 100
Average is:470
Grade: A
2. Program to find amount for given amount for given cost-
quantity-discount.
bill = int(input("Enter bill amount:"))
discount = int(input("Enter discount percentage:"))
output = bill - (bill * discount / 100)
print("After discount your bill is: ", output)
OUTPUT:
Enter bill amount: 2500
Enter discount percentage: 15
After discount your bill is: 2125.0
3. Program to calculate cost perimeter-wise/ area-wise.
L = int(input("Length is : "))
W = int(input("Width is: "))
area = L * W
perimeter = 2 * ( L+W)
print("Area of Rectangle : ",area)
print("Perimeter of Rectangle : ",perimeter)
OUTPUT:
Length is: 10
Width is: 5
Area of Rectangle: 50
Perimeter of Rectangle: 30
4. Program to calculate simple interest
p = float(input("Enter the principal amount: "))
t = float(input("Enter the time in years: "))
r = float(input("Enter the interest rate: "))
si = (p * r * t )/ 100
print("Simple Interest = %.2f" %si)
OUTPUT:
Enter the principal amount: 100000
Enter the time in years: 1
Enter the interest rate: 12
Simple Interest = 12000.00
5. To calculate profit-loss for given Cost and Sell Price
CP = float(input(" Please Enter the Cost Price of the product: "))
SP = float(input(" Please Enter the Sale Price of the product: "))
if(CP > SP):
amount = CP - SP
print("Total Loss Amount = {0}".format(amount))
elif(SP > CP):
amount = SP - CP
print("Total Profit = {0}".format(amount))
else:
print("There is no Profit no Loss....")
OUTPUT
Please Enter the Cost Price of the product: 6000
Please Enter the Sale Price of the product: 4700
Total Loss Amount = 1300.0
6. To calculate EMI for Amount, Period and Interest.
principal = 657432;
rate = 9;
time = 6;
r = rate/(12*100)
t = time*12
print("Monthly EMI is= ", round(( principal * r * pow (1 + r, t) ) / ( pow (1 + r, t ) -1 ) ) )
OUTPUT:
Monthly EMI is= 11851
7. To calculate tax (examples from GST/Income Tax)
Original_price = 100
Net_price = 124.7
GST_amount = Net_price - Original_price
GST_percent = ((GST_amount * 100) / Original_price)
print("GST = ",end='')
print(round(GST_percent),end='')
print("%")
OUTPUT:
GST = 25%
8. To find the largest and smallest numbers in a list.
Approach :
Read input number asking for length of the list using input() or raw_input().
Initialise an empty list list = [].
Read each number using a for loop.
In the for loop append each number to the list.
Now we use predefined function max() to find the largest element in a list.
Similarly we use another predefined function min() to find the smallest
element in a list.
lst = []
num = int(input('How many numbers: '))
for n in range(num):
numbers = int(input('Enter number '))
lst.append(numbers)
print("Maximum element in the list is :", max(lst))
print( "Minimum element in the list is :", min(lst))
OUTPUT:
How many numbers: 5
Enter Number: 70
Enter Number:50
Enter Number:20
Enter Number:60
Enter Number:40
Maximum element in the list is : 70
Minimum element in the list is : 20
9. To check the number is negative or positive.
n=int(input("Enter number: "))
if(n>0):
print("Number is positive")
else:
print("Number is negative")
OUTPUT:
Enter number : 12
Number is positive
10. To find the sum of squares of the first 100 natural
numbers.
def sqsum(n) :
sm = 0
for i in range(1, n+1) :
sm = sm + pow(i,2)
return sm
n=5
print(sqsum(n))
OUTPUT:
55
11. To find whether a string is a palindrome or not.
n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")
OUTPUT:
Enter number:121
The number is a palindrome!
12. To compute xn, for given two integers x and n.
num = int(input("Enter the base number"))
exp = int(input("Enter the exponent"))
power = num ** exp
print("Result is =",power)
Output
Enter the number= 2
Enter the exponent= 5
Result is = 32
13. To compute the greatest common divisor of two
integers.
num1 = float(input(" Please Enter the First Value Num1 : "))
num2 = float(input(" Please Enter the Second Value Num2 : "))
a = num1
b = num2
while(num2 != 0):
temp = num2
num2 = num1 % num2
num1 = temp
gcd = num1
print("\n HCF of {0} and {1} = {2}".format(a, b, gcd))
OUTPUT:
Please Enter the First Value Num1 : 15
Please Enter the Second Value Num2 : 10
HCF of 15 and 10 is= 5
14. To compute the least common multiple of two
integers.
a=int(input("Enter the first number:"))
b=int(input("Enter the second number:"))
if(a>b):
min1=a
else:
min1=b
while(1):
if(min1%a==0 and min1%b==0):
print("LCM is:",min1)
break
min1=min1+1
OUTPUT:
Enter the first number:5
Enter the second number:3
LCM is: 15
15. Write a program to Import numpy as `np` and print the
version number.
import numpy as np
print(np.__version__)
OUTPUT:
1.12.0
16. Program to convert a list of numeric value into a
1DNumPy array.
import numpy as np
l = [12.23, 13.32, 100, 36.32]
print("Original List:",l)
a = np.array(l)
print("One-dimensional NumPy array: ",a)
OUTPUT:
Original List: [12.23, 13.32, 100, 36.32]
One-dimensional NumPy array: [ 12.23 13.32 100. 36.32]
17. To create a numPy array with all values as True or False.
import numpy as np
print(np.all([[True,False],[True,True]]))
print(np.all([[True,True],[True,True]]))
print(np.all([10, 20, 0, -50]))
print(np.all([10, 20, -50]))
OUTPUT:
False // one of the element is false then false
True // None of the elements is false then True
False // one of the element is zero then false
True // none of the element is zero then True
18. To extract all odd numbers from numPy array.
start = int(input("Enter the start of range: "))
end = int(input("Enter the end of range: "))
for num in range(start, end + 1):
if num % 2 != 0:
print(num, end = " ")
Output:
Enter the start of range: 3
Enter the end of range: 11
3 5 7 9 11
19. To extract all even numbers from numPy array.
start = int(input("Enter the start of range: "))
end = int(input("Enter the end of range: "))
for num in range(start, end + 1):
if num % 2 = 0:
print(num, end = " ")
Output:
Enter the start of range: 3
Enter the end of range: 11
4 6 8 10
20. NumPy: Create an array with values ranging from 1 to 10.
import numpy as np
x = np.arange(1, 10)
print(x)
OUTPUT:
1 2 3 4 5 6 7 8 9
21. NumPy program to reverse an array (first element
becomes last).
import numpy as np
import numpy as np
x = np.arange(1, 10)
print("Original array:")
print(x)
print("Reverse array:")
x = x [ :: -1 ]
print(x)
OUTPUT:
Original Array: 1 2 3 4 5 6 7 8 9
Reverse Array: 9 8 7 6 5 4 3 2 1
22. Write a NumPy program to create a 3x3 matrix with
values ranging
from 2 to 10.
import numpy as np
x = np.arange(2, 11).reshape(3,3)
print(x)
OUTPUT:
[[ 2 3 4]
[ 5 6 7]
[ 8 9 10]]
Data Management: SQL Commands
1. Write a SQL query to create database “Student”.
Ans:- CREATE Database Student
2. Write a SQL query to create “student” table with the student id, class, section,
gender, name, dob, and marks as attributes where the student id is the primary key.
Ans: CREATE TABLE Student ( ID Int primary key,
Class VARCHAR(100),
gender char
name text[20]
Dob date/time
Marks int );
Output:
Table: Student
ID (primary key) CLASS GENDER NAME DOB Marks
3. To insert the details of at least 4 student in the above table Student.
Ans: Insert into Student(ID, Class, Gender, Name, Dob) VALUES (1, 11, ‘M’, ‘Arun’ , 19-02-93, 50);
Insert into Student(ID, Class, Gender, Name, Dob) VALUES (2, 12, ‘M’, ‘Vikas’, 13-02-91, 75);
Insert into Student(ID, Class, Gender, Name, Dob) VALUES (3, 11, ‘F’, ‘Shikha’, 11-03-99, 70);
Insert into Student(ID, Class, Gender, Name, Dob) VALUES (4, 10, ‘M’, ‘Naman’, 12-08-93, 60);
Output:
Table: Student
ID (primary key) CLASS GENDER NAME DOB Marks
1 11 M Arun 19-02-93 50
2 12 M Vikas 13-02-91 75
3 11 F Shikha 11-03-99 70
4 10 M Naman 12-08-93 60
4. To delete the details of a student Vikas in the above table.
Ans: DELETE * from Student where name= “Vikas”;
5. To display the entire content of table on screen.
Ans: SELECT * from Student;
6. To increase marks by 5% for those students, who have Rno more than 20
Ans: UPDATE table Student Set Marks=Marks + (Marks x 5 /100) where ID > 20;
7. To display ID, Name & Marks of those students, who are scoring marks more than 50.
Ans: SELECT ID, Name, Marks from Student where marks> 50;
8. To find the average of marks from the student table.
Ans: SELECT AVG(Marks) from Student.
9. To find the number of students, whose gender are male.
Ans: SELECT COUNT(Gender=’M’) from Student;
10.To add a new column email of appropriate data type.
Ans: ALTER TABLE Student ADD( Email varchar[25]);
11.To find the minimum marks obtained by students
Ans: Select Min (Marks) from Employee.
12.To find the maximum marks obtained by students
Ans: Select Max(Marks) from Employee.
13.To display the information all the students, whose name starts with ‘A’.
Ans: SELECT * from Student where Name Like= “ A%”.
14.To display ID, Name of those students, who are born between ‘1990-01-01’ and
‘2000-01-01’
Ans : SELECT ID, Name from Student BETWEEN (1990-01-01) AND (2000-01-01)
15. To display ID, Name, DOB, Marks of those male students in ascending order of their
names.
Ans: SELECT ID, Name, Dob from Student ORDER by Name;
16.To display ID, Name, DOB, Marks of those male students in descending order of their
names.
Ans: SELECT ID, Name, Dob from Student ORDER by Name desc;