Practice Questions
Practice Questions
CODE:
def Longlines():
f=open("Lines.txt","r")
print("No. of lines with atleast 10 words are:")
for line in f:
words=line.split()
if len(words)>=10:
print(line)
f.close()
def CountWas():
count=0
f=open("Lines.txt","r")
for line in f:
words=line.split()
for word in words:
if word=="was":
count+=1
print("No. of occourances of word 'was' is:",count)
f.close()
Longlines()
CountWas()
Q2. Create the given table Tech_course in MYSQL and insert the following records in it.
Write the Python - MYSQL connectivity code to display all course details whose fees is more
than 10000. [5M]
C_ID C_Name Fees Startdate Term_ID
C201 MBA 90000 2024-07-02 101
C202 MTech 30000 2023-11-15 105
C203 Data Science 65000 2022-10-01 102
C204 Cyber Security 9000 2021-09-15 104
C205 Cloud Computing 18000 2022-11-01 101
C206 Machine Learning 16000 2024-07-25 103
Note the following to establish connectivity between Python and MYSQL.
Username: root
Host name: localhost
Password: tiger
Database name: Courses
a. Consider the table Tech_course and solve the following queries. [4M]
(i) Display minimum and maximum fees of the course offered.
(ii) Display all courses details whose name starts with ‘D’.
(iii) Display course name in order of startedate.
(iv) Count and Display no. of courses offered Term_ID wise.
CODE:
import mysql.connector as mycon
mydb=mycon.connect(host="localhost",user="root",password="",datab
ase="practice")
cursor=mydb.cursor()
querry="SELECT * FROM tech_course WHERE Fees>10000;"
cursor.execute(querry)
data=cursor.fetchall()
for i in range(len(data)):
print(data[i])
print("\n")
print("\n")
q2="SELECT * FROM tech_course where CName LIKE 'D%';"
cursor.execute(q2)
d2=cursor.fetchall()
for j in range(len(d2)):
print(d2[j])
print("\n")
print("\n")
CODE:
def CountVowels():
vowel="aeiouAEIOU"
vcount=ccount=0
f=open("test.txt","r")
for line in f:
for char in line:
if char in vowel:
vcount+=1
elif char not in vowel:
ccount+=1
print("No. of vowels in file:",vcount)
print("No. of consonent in file:",ccount)
CountVowels()
Q4.Stack operations for list [custname,phoneno,city]
CODE:
def isEmpty(stk):
if stk==[]:
return True
else:
return False
def Push(stk,a):
stk.append(a)
def Pop(stk):
if isEmpty(stk):
return "Underflow"
else:
item=stk.pop()
if len(stk)==0:
top=None
else:
top=len(stk)-1
return item
def Display(stk):
if isEmpty(stk):
return "Underflow"
else:
top=len(stk)-1
print(stk[top],"<---top")
for i in range(top-1,-1,-1):
print(stk[i])
def Peek(stk):
if isEmpty(stk):
print("Underflow")
else:
top=len(stk)-1
return stk[top]
#__main__
Stack=[]
top=None
while True:
print("STACK OPERATIONS")
print("1.Push")
print("2.Pop")
print("3.Display")
print("4.Peek")
Q.6 Consider the table Teacher and solve the following queries
a. Display all the female teacher details whose salary is more than 15000.
b. Display no. of teachers department wise.
c. Increase the salary by 5% of teachers from ‘Computer Science’ department.
d. Display all the teacher details in ascending order of DOJ.
Table: Employee
Empid Name DOB DeptID Designation Salary
120 Alisha 23-01-1988 D001 Manager 75000
123 Nitin 10-10-1977 D002 Assistant Manager 59000
129 Navjot 12-07-1991 D003 Supervisor 40000
130 Jimmy 30-12-1990 D004 Sales Representative 34000
131 Faiza 06-04-1987 D001 Department Manager 65000
Username: root
Host name: localhost
Password: tiger
Database name: Company
Write the SQL queries given below and show the result to examiner.
(i) To display the names of all the white coloured vehicles.
(ii) To display name of vehicle and capacity of vehicles in ascending order of their sitting
capacity.
(iii) Update the charges of Mercedes car as 50 .
(iv) Add a column Pnum in the table Cabhub with datatype as integer.