Practical Q&sol (14-25) 2024
Practical Q&sol (14-25) 2024
def Arrange(wd):
p=len(wd) word=''
for i in range(65,91):
for j in range(0,p):
ch=wd[j] if (ch==chr(i)
or ch==chr(i+32)):
word=word+ch
program
wd=wd.lower() wd1=Arrange(wd)
return c
#main Program
n=int(input("Enter a number:"))
p=Prime(n) if (p==2):
number")
CountHeShe():
if os.path.isfile("LIFE.TXT"):
fb = open("LIFE.TXT", 'r')
Ctr = 0
while True:
if not line:
else:
else:
CountHeShe()
import os
def ReplaceSpace():
if os.path.isfile("SPACE.TXT"):
Ctr = 0
while True:
Str = line.rstrip().split()
# Words are written into 'RSPACE.TXT' file with adding a single space instead
of multiple spaces
for i in range(len(Str)):
File1.close()
File2.close()
else:
ReplaceSpace()
Ch = 'Y'
Ch = input().upper()
if Ch == 'N' or Ch == 'NO':
break
return Top
PopNumbers(Stack, Top):
else:
return Top
ShowNumbers(Stack, Top):
else:
i = Top
print(Stack[i])
i -= 1
while (True):
print()
print ('Number Operation')
print()
if (Opt == '1') :
ShowNumbers(Stack, Top)
break
Q19.
PROGRAM NO 20:
Consider the following tables product and client. Further answer the questions given below.
Queries
Q.1.
To display the details of those clients whose city is “delhi”
Ans:
Select * from client where city=’Delhi’;
Q.2
To display the details of products whose price is in the range of 50 to 100 Ans:
Select * from product where price between 50 and 100; select
* from product where price>=50 and price<=100;
Q.3
TO DISPLAY THE client name ,city from table client and productname and price from the table
product with their corresponding matching p_id Ans:
Select clientname, city, productname, price from client, product where client.p_id=product.p_id;
Q.4
To increase the price of the product by 10 Ans:
Update product set price=price+10;
Q.5.
Select distinct city from client; Ans:
Delhi
Mumbai
Banglore
PROGRAM NO 21:
Consider the following tables CONSIGNOR and CONSIGNEE. Further answer the questions
given below.
TABLE:CONSIGNOR
Queries
Q1.
To display the names of all the consignors from Mumbai Ans
Select cnorname From consignor Where city=’mumbai’;
Q2.
To display the cneeid,cnorname,cnoradress,cneenmae,cneeaddress for every consignee Ans
Select cneeid,cnoraddress,cneename,cneeaddess From consignor, consignee
Where consignor.cnorid=consignee.cnorid;
Q3.
To display consignee details in ascending order of cneename. Ans
Select * From consignee Order by cneename;
Q4.
To display number of consignee from each city.
Ans
Select cneecity,count(cneecity) From consignee Group by cneecity;
Q5.
Select distinct cneecity from consignee;
Ans
Mumbai
Program 22:
def count_alpha():
lo=0
with open("story.txt") as f:
while True:
c=f.read(1)
if not c:
break
print(c,end='')
if((c>='A' and c<='Z') or (c>='a' and c<='z')):
lo=lo+1
print("total lower case alphabets: “, lo)
#function calling
count_alpha()
Output:
Write a python program to read a file named “story.txt”, count and print total
words starting with “a” or “A” in the file?
Solution: def
count_words():
w=0 with
open("Poem.txt") as f:
for line in f:
for word in line.split():
if(word[0]=="a" or word[0]=="A"):
print(word) w=w+1
print("total words starting with 'a' are ",w)
# function calling count_words()
PROGRAM NO:21 Write records of customer into result.csv. The fields are as following:
Field 1 Data Type
StudentID Integer
StudentName String
Score Integer
OUTPUT:
PROGRAM 24:
Read a CSV file students.csv and print them with tab delimiter. Ignore first row header to print in
tabular form.
OUTPUT:
Q25.
The code given below inserts the following record in the table Student:
RollNo – Integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is tiger
The table exists in a MYSQL database named school.
The details (RollNo, Name, Clas and Marks) are to be accepted from the user.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the command that inserts the record in the table Student. Statement
3- to add the record permanently in the database
import mysql.connector as mysql
def sql_data():
con1=mysql.connect(host="localhost",user="root", 2+3 11 password="tiger",
database="school")
mycursor=_________________ #Statement 1
rno=int(input("Enter Roll Number :: "))
name=input("Enter name :: ")
clas=int(input("Enter class :: "))
marks=int(input("Enter Marks :: "))
querry="insert into student values({},'{}',{},{})".format(rno, name, clas, marks)
______________________ #Statement 2
______________________ # Statement 3
print("Data Added successfully")
SOLUTION.
Ans:
Statement 1: con1.cursor()
Statement 2: mycursor.execute(querry)
Statement 3: con1.commit()