Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
COMPUTER SCIENCE
PYTHON PRACTICAL PROGRAMS
1. Program to obtain length and breadth of a rectangle and calculate its area.
Solution.
#to input length and breadth of a rectangle and calculate its area
length = float( input("Enter length of the rectangle : "))
breadth= float( input (" Enter breadth of the rectangle: "))
area=length * breadth
print ("Rectangle specifications ")
print ("Length = ", length)
print ("breadth ", breadth)
print ("Area = ", area)
if num > 1:
for n in range(2, val):
if (val % n) == 0:
break
else:
print(val)
Solution.
num=int(input("Enter the number:"))
for a in range (2, num, 2):
for b in range (1, a, 2):
print (b, end =(' '))
print ()
SOURCE CODE:
Lst=eval(input ( " Enter list :"))
length=len(Lst)
element=int(input( " Enter element :"))
count=0
for i in range(0, length):
if element==Lst [i]:
count += 1
if count == 0:
print (element, "not found in given list")
else:
print(element, "has frequency as", count, "in given list")
for i in range(L):
num=int(input("Enter the number"))
a.append(num)
print (a)
n=len(a)
for p in range(0,n-1):
for i in range(0,n-1):
if a[i]>a[i+1]:
t=a[i]
a[i]=a[i+1]
a[i+1]=t
print("The sorted list is : ", a)
17.Program to input two numbers and print their LCM and HCF.
SOURCE CODE:
X=int(input("Enter first number:"))
Y= int (input("Enter second number:"))
if X >Y:
smaller = Y
else:
smaller = X
for i in range(1, smaller + 1):
if((X % i==0) and (Y % i == 0) ) :
hcf = i
lcm=(X* Y) / hcf
print("The H.C.F. of", X, "and ", Y, "is", hcf)
print("The L.C.M. of", X, "and ", Y, "is", lcm)
18.Write a python function sin(x, n) to calculate the value of sin(x) using its
taylor series expansion up to n terms.
SOURCE CODE:
import math
def fact(k):
if k<=1:
return 1
else:
return k*fact(k-1)
step=int(input("How many terms : "))
x=int(input("Enter the value of x :"))
sum=0
for i in range(step+1):
sum+=(math.pow(-1,i)*math.pow(x,2*i+1))/fact(2*i+1)
print("The result of sin",'(', x, ')', "is :", sum)
SQL Program
SQL PROGRAMS
PART-B
Exp A: CREATE A STUDENT DATABASE AND COMPUTE THE RESULT.
2) Add record into the table for 5 students, using insert command.
Query 2:
insert into student values('101','arun','69','70','55','90');
insert into student values('102','Sunny','39','50','58','67');
insert into student values('103','Prajwal','67','40','59','89');
insert into student values('104','Satish','20','30','56','45');
insert into student values('105','Rekha','19','70','89','40');
Query5:
Alter table student add (total number (3));
7) Find the min, max, sum, and average of the marks in a student marks table.
Query7:
SELECT min(total) FROM student;
SELECT max(total) FROM student;
SELECT sum(total) FROM student;
SELECT avg(total) FROM student;
8) Add to new fields to the table:
*percentage number(3)
*result varchar2(10)
Query8:
Alter table student add (percentage number (3), result varchar2(10));
10)Compute the result as "pass" or "fail" by checking if the student has scored
more than 35 marks in each subject.
Query10(a):
Update student set result='pass' where Comp>=35 and Maths>=35 and
Physics>=35 and Chem>=35;
Query 10(b):
Update student set result='fail' where Comp<35 or Maths<35 or
Physics<35 or Chem<35;
max(scheduledate) min(scheduledate)
---------------------------- --------------------------------
23-jan-2016 12-dec-2019