Professional Documents
Culture Documents
1.
def check(a):
c=0
for i in range(2,a):
if a%i==0:
c=c+1
if c==0:
print("The given number is prime")
else:
print("The given number is not prime")
result = fun(list, x)
print(result)
2.
def count(a):
v=0
c=0
u=0
l=0
for i in a:
if i in "AEIOUaeiou":
v=v+1
elif i not in "AEIOUaeiou" and i.isalpha():
c=c+1
for i in a:
if i.isupper():
u=u+1
elif i.islower():
l=l+1
print("Number of vowels-",v)
print("Number of consonants-",c)
print("Number of Uppercase letters-",u)
print("Number of Lowercase letters-",l)
3.
def fun(list, x):
list.sort()
low = 0
high = len(list) - 1
mid = 0
while low <= high:
mid = (high + low) // 2
if list[mid] < x:
low = mid + 1
elif list[mid] > x:
high = mid - 1
else:
return 1
return -1
list = [23,46,2,4,5]
x = int(input("Enter the element to search: "))
4.
def count():
f=open("DIARY.TXt")
a=f.read()
b=a.lower()
me=0
my=0
for i in b:
if i=="me":
me=me+1
if i=="my":
my=my+1
print("Number of me-",me)
print("Number of my-",my)
count()
5.
def fun():
f=open("Places.txt", "r")
lines=f.readlines()
for i in lines:
if i[0]=="P" or i[0]=="S":
print(i)
f.close()
fun()
6.
def EUCount():
f=open("IMP.TXT", "r")
str=f.read()
str1=str.split()
l1=0
l2=0
for i in str1:
for j in i:
if j in "eE":
l1=l1+1
elif j in "uU":
l2=l2+1
print("E:", l1)
print("U:", l2)
f.close()
EUCount()
7.
def fun():
f=open("STORY.TXT", "r")
lines=f.readlines()
for i in lines:
if i[-1] in "aeiouAEIOU":
print(i)
f.close()
fun()
8.
def copy():
f=open("FAIPS.TXT", "r")
g=open("DPS.TXT", "a")
str=f.read()
str1=str.split()
for i in str1:
for j in i:
if j.isupper():
f.write(i)
f.close()
g.close()
copy()
9.
import pickle as p
def fun():
f=open("BOOK.DAT", "rb")
No=input("Enter the BookNo to search: ")
while True:
try:
rec=p.load(f)
for i in rec:
if i[0]==No:
print(i)
except:
break
f.close()
fun()
10.
import os
import pickle
11.
import pickle as p
def fun():
f=open("BOOK.DAT", "rb")
No=input("Enter the BookNo to search: ")
while True:
try:
rec=p.load(f)
for i in rec:
if i[0]==No:
print(i)
except:
break
f.close()
fun()
12.
import csv
while True:
Option = input("1:CreateCSV 2:CreateCSVAll 3:ShowCSV
4:Quit ")
if Option == "1":
CreateCSV1()
elif Option == "2":
CreateCSV2()
elif Option == "3":
ShowAll()
else:
break
13.
import csv
al=["id", "password"]
a=[["useridl", "password1"],["userid2",
"password2"],["userid3", "password3"],["userid4",
"password4"],["userid5", "password5"]]
b=input ("Enter username")
myfile=open ("sample.csv", "w+", newline="\n")
myfilel=csv.writer (myfile)
myfilel.writerow(al)
myfilel.writerows (a)
myfile.seek(0)
myfile2=csv.reader (myfile)
for i in myfile2:
if i[0]==b:
print("The paswword is", i[1])
myfile.close()
14.
Stack=[]
List=[0,1,2,4] # Assuming
def PushS(List):
Stack.append(List)
def PopS(List):
if len(Stack) == 0 :
print("Stack is empty!")
else:
print(Stack.pop())
15.
student=[]
list=[[6,"Raju"],[7,"Rohit"]] # Assuming
def push(list):
student.append(list)
def pop(student):
if len(student) == 0 :
print("Stack is empty!")
else:
print(student.pop())
def show(student):
if len(student) == 0 :
print("Stack is empty!")
else:
for i in range(len(student)-1,-1,-1):
print(student[i])
16.
import mysql.connector as con
def createTable():
db=con.connect(host='localhost',user="root",password="",d
atabase="emp")
cur=db.cursor()
cur.execute("create table EMPLOYEE(eno int(5),name
varchar(30),age int(3),salary float(9,2),doj date,address
varchar(30))")
db.commit()
db.close()
def insert():
db=con.connect(host='localhost',user="root",password="",d
atabase="emp")
cur=db.cursor()
eno=int(input("Enter Eno of employee: "))
name=input("Enter Name of employee: ")
age=input("Enter Age of employee: ")
sal=int(input("Enter Salary of employee: "))
doj=input("Enter Date of Joining of employee (YYYY-MM-
DD): ")
address=input("Enter Address of employee: ")
cur.execute("insert into EMPLOYEElues
({},'{}',{},{},'{}','{}')".format(eno,name,age,sal,doj,addr
ess))
db.commit()
db.close()
def display():
db=con.connect(host='localhost',user="root",password="",d
atabase="emp")
cur=db.cursor()
cur.execute("select * from EMPLOYEE")
r=cur.fetchall()
for i in r:
print(i)
print()
db.commit()
db.close()
def update():
db=con.connect(host='localhost',user="root",password="",d
atabase="emp")
cur=db.cursor()
cur.execute("update EMPLOYEE set salary=salary+1000 where
salary<80000")
db.commit()
db.close()
def delete():
db=con.connect(host='localhost',user="root",password="",d
atabase="emp")
cur=db.cursor()
eno=int(input("Enter eno of employee: "))
cur.execute("delete from EMPLOYEE where
eno={}".format(eno))
db.commit()
db.close()
SECTION-B (SQL)
Q1. Consider the tables EMPLOYEE and SALGRADE given below and
answer (a) and (b)parts of this question.
(iii) To display the content of the entire EMPLOYEEs table, whose DOJ
is in between ‘09-Feb-2006’ and ‘08-Aug-2009’.
>>select * from EMPLOYEE
where DOJ between "2006-02-09" and "2009-08-08";
COUNT(SGRADE) SGRADE
2 S03
3 S02
1 S01
MIN(DOB) MAX(DOB)
1980-01-13 2010-02-10
SGRADE SALARY+HRA
S02 44000
Q2. Study the following table and write SQL queries for questions (i) to
(iv) and output for (v) and (vi).
(i) Write SQL query to display Pname, Quantity and Rate for all the
orders that are either Pencil or Pen.
>>Select pname,quantity,rate from orders
Where pname=”pen or pname=”pencil”;
(ii) Write SQL query to display the orders which are not getting any
Discount.
>>Select * from orders
Where discount is NULL;
(iii) Write SQL query to display the Pname, Quantity and Sale_date for
all the orders whose total cost (Quantity * Rate) is greater than 500.
>>Select pname,quantity, Sale_date from orders
Where Quantity * Rate>500;
(iv) Write SQL query to display the orders whose Rate is in the range
20 to 100.
>>Select * from orders
Where rate between 20 and 100;
(v) SELECT Pname, Quantity from Orders WHERE Pname LIKE(‘_e%’);
Pname Quantity
Pen 10
Pencil 20
(ii)To display cost of all the books published for FIRST PUBL.
>>Select price from books
Where publishers=”FIRST PUBL.”;
(iii)Depreciate the price of all books of EPB publishers by 5%.
Update books
>>Set price=(price –(price*(5/100)))
Where publishers=”epb”
(i) To show all information of students where capacity is more than the
no. of students in order of rtno.
>>Select * from schoolbus
Where capacity>noofstudents
Order by rtno;
(ii) To show area_covered for buses covering more than 20 km., but
charges less than 80000.
>>Select area_covered from schoolbus
Where distance>20 and charges<80000;
(iv) To show rtno, area_covered and average cost per student for all
routes where average cost per student is—charges/noofstudents.
>>Select rtno, area_covered, charges/noofstudents “average cost”;
(v) Add a new record with the following data:
(11, “Motibagh”,35,32,10, “kisan tours”, 35000)
>>Insert into schoolbus values (11, “Motibagh”,35,32,10, “kisan tours”,
35000);
avg(charges)
81666.6666667
Table : ARRIVALS
NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
11 Wood Double 23/03/03 25000 25
Comfort Bed
12 Old Fox Sofa 20/02/03 17000 20
13 Micky Baby 21/02/03 7500 15
cot