0% found this document useful (0 votes)
34 views29 pages

XI - IP Practical File

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views29 pages

XI - IP Practical File

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Practical File

For
AISSCE 2024-25 Examination
As a part of the Informatics Practices Course (065)

SUBMITTED BY:
Name:
Roll no. :
Class: XI-B

Under the Guidance of:


Mr. Manoj Kumar Singh
(PGT Comp Sc.)
SV Rouse Avenue
(DDU Marg, New Delhi -110002)
INDEX
S No. Topic Pg.No. Signature

Q1. Write a python script to obtain 3 numbers and print 4

their sum.

Q2. Write a program to obtain temperature in Celsius and 5

convert it into Fahrenheit using formula C*9/5+32=°F.

Q3. Write a program to input a number and print it’s first 6

five multiples.

Q4. Write a program that accepts a number and checks 7

whether no. is even or odd.

Q5. Write a program to read 3 numbers in 3 variables and 8

swap first 2 variables with the sums of first and


second, second and third numbers respectively.

Q6. Write a program that accepts 3 numbers and print 9

largest of the three. a) Make use of if statement b)


Make use of if-elif.

Q7. Program that reads 2 numbers and an arithmetic 10

operator and display the result according to operator.

Q8. Program to print whether a character is upper/lower 11

case, digit or special character.

Q9. Write a program that reads 3 numbers and prints them 12

in ascending order.

Q10. Write a program to calculate factorial of a number. 13


Q11. WAP to print the sum of natural numbers between 1 15

to 10.

Q12. WAP to check whether a number is prime or not. 16

Q13. Program to print Fibonacci series of first 20 elements. 17

Q14. Program to print patterns. 18

Q15. WAP that reads an integer and reverse it. 19

Q16. WAP that accepts and integer and print the sum of its 20

digits.

Q17. WAP to input 2 numbers and print their LCM & GCD. 21

Q18. WAP that reads a line and tell no. of uppercase, 22

lowercase, alphabets digit.

Q19. WAP that reads a string & display it in reverse order. 23

Q20. WAP to find minimum elements from a list along with 24

its index in list.

Q21. WAP to search for an element in a given list of 25

numbers.

Q.22 SQL Program 26


Question1.
Write a python script to obtain 3 numbers and print their sum.
Answer:
n1= int(input("enter a number 1:"))
n2 =int(input("enter a number2:"))
n3 =int(input("enter a number3:"))
sum=n1+n2+n3
print("sum of three number are:",sum)
Output:
Question2.
Write a program to obtain a temperature in celsius and convert it into fahrenheit
using formula, C×9/5+32=°F
Answer:
celsiusTemp=float(input("enter a temperature in celsius:"))
fahrenheitTemp=(celsiusTemp*9/5)+32
print("the temperature in fahrenheit is",fahrenheitTemp)

Output:
Question3.
Write a program to input a number and print it first five multiples.
Answer:
n=int(input("enter a number:"))
for x in range(n,n*6,n):
print(x)
Output:
Question4.
Write a program that accepts a number and checks whether number is even or
odd.
Answer:
n=int(input("enter a number"))
if(n%2==0):
print("even")
else:
print("odd")
Output:
Question5.
Write a program to read 3 numbers in 3 variables and swap first 2 variables
with the sum of first and second, second and third numbers respectively.
Answer:
a=int(input("enter a no1:"))
b=int(input("enter a no2:"))
c=int(input("enter a no3:"))
a=a+b
b=b+c
print("after swapping the value of a=",a)
print("after swapping the value of b=",b)
Output:
Question6.
Write a program that accepts 3 numbers and print largest of the three.
1) Make use of if-elif
Answer:
n1=float(input("enter a number1:"))
n2=float(input("enter a number2 :"))
n3=float(input("enter a number3 :"))
if(n1>=n2 and n1>=n3):
print("highest n1")
elif(n2>=n1 and n2>=n3):
print("highest n2")
else:
print(n3)

Output :
Question7.
Program that reads 2 numbers and an arithmetic operator and display the result
according to operator.
Answer:
a=float(input("enter first number:"))
b=float(input("enter second number:"))
op=input("enter operator[+-*/%]")
result=0
if op=="+":
print(a+b)
elif op=="-":
print(a-b)
elif op=="*":
print(a*b)
elif op=="/":
print(a/b)
else:
print("invalid operator!!")
print(a,op,b,'=',result)
Output:
Question8. Program to print whether a character is an uppercase/lowercase,
digit or special character.

Answer:
ch=input("enter a character:")
if (ch>="A" and ch<="Z"):
print("uppercase character")
elif (ch>"a" and ch<="z"):
print("lowercase character")
elif (ch>="0"and ch<="9"):
print("you entered digit")
else:
print("you entered special
character")
Output:
Question9. Write a program that read 3 numbers and prints them in ascending
order.

Answer:

x=int(input("Enter first number"))


y=int(input("Enter second number"))
z=int(input("Enter third number"))
min=mid=max=None
if x<y and x<z:
if y<z:
min,mid,max=x,y,z
else:
min,mid,max=x,z,y
elif y<x and y<z:
if x<z:
min,mid,max=y,x,z
else:
min,mid,max=y,z,x
else:
if x<y:
min,mid,max=z,x,y
else:
min,mid,max=z,y,x
print("Numbers in ascending order:",min,mid,max)

Output:
Question10.
Write a program to calculate factorial of a number.
Answer:
def factorial (n):
if n<0:
return 0
elif n==0 or n==1:
return 1
else:
fact=1
while (n>1):
fact *= n
n-=1
return fact
num=5
print("Factorial of",num,"is",factorial(num))
Output:
Question11.
Write a program to print the sum of natural numbers between 1 to 10.
Answer :
sum = 0

for n in range(1, 11):


sum += n
print("Sum of natural numbers up to", n, "is", sum)

Output :
Question12.
Write a program to check whether a number is prime or not.
Answer:
n = int(input("Enter a number: "))

if n > 1:
for i in range(2, n):
if (n % i) == 0:
print("Number is not prime:", n)
break
else:
print("Number is prime")
else:
print("Number is not prime")

Output:
Question13.
Program to print Fibonacci series of first 20 elements.
Answer:
first=0
second=1
print(first)
print(second)
for a in range(1,19):
third=first+second
print(third)
first,second=second,third
Output:
Question14.
Program to print pattern.

Answer:
a) for r in range(1,6):
for c in range(1,r+1):
print ("*",end=" ")
print( )

Output :

b)

for r in range(1,6):
for c in range(1, r + 1):
print(c, end=" ")
print()

Output :
Question15.

Write a program that reads an integer and reverse it.

Answer:

num = 1234

temp = num

reverse = 0

while num > 0:

remainder = num%10

reverse =(reverse*10) + remainder

num=num//10

print(reverse)

Output :
Question16.
Write a program that accepta an integer and print the sum of its digits.
Answer:
num = input("Enter an integer: ")
sum = 0
for i in num:
sum += int(i)
print(sum)

Output:
Question17.

Write a program to input 2 numbers and print their LCM and GCD.

Answer:

num1=12

num2=14

for i in range(1,max(num1,num2)):

if num1%i==num2%i==0:

gcd=i

lcm=(num1*num2)//gcd

print("LCM of",num1,"and",num2,"is",lcm)

print("GCD of",num1,"and",num2,"is",gcd)

Output:
Question18.
Write a program that reads a line and tell number of uppercase, lowercase,
alphabets digit.
Answer:
Write a program that reads a line and tell number of uppercase, lowercase,
alphabets digit.
Answer :
s=input("enter a sentence:")
a,d,u,l=0,0,0,0
for c in s:
if c.isalpha():
a=a+1
if c.isdigit():
d=d+1
elif c.isupper():
u=u+1
elif c.islower():
l=l+1
print("no of alphabets=",a)
print("no of digits=",d)
print("no of uppercase letters=",u)
print("no of lowercase letters=",l)
Output :
Question19. Write a program that reads a string and display it in reverse order.

Answer:

string="Hello World"

output=" "

for i in range(len(string)-1,1,-1):

output+=string[i]

output+=string[i-1]

output+=string[i-2]

print(output)

Output:
Question20.
Write a program to find minimum element from a list along with its index in
list.
Answer :
L=[2,58,95,999,65,32,15,17,45]
print(L)
m=min(L)
print("the minimum element is:",m)
print("index of minimum element is:"
,L.index(m))

Output :
Question21.
Write a program to search for an element in a given list of number.
Answer:
mylist=[ ]
print("enter five elements for the list:")
for i in range (5):
val=int(input())
mylist.append(val)
print("enter an elements to be searched:")
elem=int(input())
for i in range(5):
if elem==mylist[i]:
print("/nelement found at index:",i)
print("element found at
position:",i+1)

Output:
Question22.

a) Create a student table and insert data. Implement the following MySQL commands
on the student table:

 ALTER table to add new add new attributes/modify data types/drop attribute
 UPDATE table to modify data
 ORDER BY to display data in ascending /descending order
 DELETE to remove tuple(s)

In this post, we are going to create student table and insert 10 student records (data) into
it.Then we will perform some MySQL queries to retrieve data from database. We will alter,
update and order data in ascending and descending order by using MySQL commands. We
will implement following MySQL command on the student table.

They are as follows

 Create a student table and insert data.


 Insert 10 student record into student table
 To add a new column city in the above table with appropriate data type
 To increase marks by 50% for those students who have marks less than 40
 To display Rno, Name, Marks of those Female students in ascending order of
their names
 To display Rno, Gender, Name, Marks in descending order of their marks
 Delete CITY column from student table
 Delete student detail from student table whose roll no is 14

Solutions
CREATE TABLE command is used to create table in MySQL. When table is created, its
columns are named; data types and sizes are also supplied for each column. One point is to
be note that each table must have at least one column.

Syntax of CREATE TABLE command is :


CREATE TABLE <table-name> (<column name1><data type1>[(size1)], <column
name2><data type2>[(size2)],<column name3><data type3>[(size3)]…………….
<column namen><data typen>[(sizen)] );

To create student table whose schema is as follows:

CREATE TABLE STUDENT (RNO INT PRIMARY KEY, NAME VARCHAR (60),
CLASS INT, SECTION VARCHAR (5), GENDER VARCHAR (10), MARKS INT);

In this way create student table with multiple columns. In this table, we declare RNO column
as the primary key of the table. The primary keys cannot allow NULL values.
Create a student table

Inserting data into table


We can add rows into table using INSERT command of SQL.

Syntax of INSERT INTO command:


INSERT INTO <table name>[ <column list> ] VALUES( <value1>, <value2>,
……………………….);

The INSERT statement adds a new row to table giving value for every column in the
row.

Note that the data values are in same order as the column names in table. We can insert
number of rows into student table. If we want to insert 10 rows into student table then we
need to specify 10 INSERT command to do it.

Also read: How to insert multiple rows into MySQL at a time

Insert 10 student record into student table

ALTER TABLE Command


We can add column using ALTER TABLE command .We can also redefine a column and
we can change the definition of existing tables. We can change the data type or size of
column using ALTER TABLE command.
To add column
Syntax of ALTER TABLE command is:
ALTER TABLE <TABLE NAME>ADD<COLUMN
NAME><DATATYPE><SIZE>[<CONSTRAINT NAME>];

To add a new column city in the above table with appropriate data type

UPDATE Command
Sometimes we need to change some or all of the values in an existing row. This can be done
using UPDATE command of SQL. WHERE Clause and SET keyword are used with
UPDATE command.

Syntax of UPDATE command


UPDATE <table name> SET <column name> <scalar expression> WHERE condition;

To update single column, one column assignment can be specified with SET clause.

To update multiple columns, multiple columns assignments can be specified with SET
clause.

To increase the marks for the student who have less than 40 by 50%, you could use the
following code

To increase marks by 50% for those students who have marks less than 40

Sorting result—- ORDER BY CLAUSE


ORDER BY clause allows sorting of query results by one or more columns. The sorting can
be done either in ascending or descending order, default order is ascending. Note that, the
data in the table is not sorted; only results that appear on the screen are sorted.

SYNTAX OF ORDER BY CLAUSE


SELECT <COLUMN NAME>[, <COLUMN NAME>,……]

FROM <TABLE NAME>[WHERE <PREDICATE>] [ORDER BY <COLUMN


NAME> ASC/DESC];

To specify the sort order, we may specify DESC for descending order or ASC for ascending
order. We can perform ordering on multiple attributes or columns
To display Rno, Name, Marks of those Female students in ascending order of their names

To display Rno, Gender, Name,Marks in descending order of their marks

ALTER TABLE Command with DROP Clause


We can remove specific columns from table using ALTER TABLE command with DROP
clause. This command is used to remove specific column from table.

Syntax of ALTER TABLE Command with DROP Clause


ALTER TABLE <TABLENAME> DROP COLUMN <COLUMNNAME>;

Drop Column CITY from student table


DELETE command
The DELETE command removes the rows from table. This removes the entire rows,not
individual field values.

Syntax of DELETE Command


DELETE FROM <TABLENAME>[WHERE CONDITION];

To remove all the contents of specific rows, the following command is used.

Delete student details from above table

b) Queries using DISTINCT, BETWEEN, IN, LIKE, IS NULL, ORDER


BY
A. Display the name of departments. Each department should be displayed once.
SELECT DISTINCT (Dept) FROM EMPLOYEE;
B. Find the name and salary of those employees whose salary is between 35000
and 40000.
SELECT Ename, salary FROM EMPLOYEE WHERE salary BETWEEN 35000
and 40000;
C. Find the name of those employees who live in guwahati, surat or jaipur city.
SELECT Ename, city FROM EMPLOYEE WHERE city IN
(‘Guwahati’,’Surat’,’Jaipur’);
D. Display the name of those employees whose name starts with ‘M’.
SELECT Ename FROM EMPLOYEE WHERE Ename LIKE ‘M%’;
E. List the name of employees not assigned to any department.
SELECT Ename FROM EMPLOYEE WHERE Dept IS NULL;
F. Display the list of employees in descending order of employee code.
SELECT * FROM EMPLOYEE ORDER BY ecode DESC;

You might also like