SQL and Python Questions
SQL and Python Questions
Table:- CABHUB
Vcod VehicleName Make Color Capacity Charges
e
100 Innova Toyota WHITE 7 15
102 SX4 Suzuki BLUE 4 14
104 C Class Mercedes RED 4 35
105 A-Star Suzuki WHITE 3 14
108 Indigo Tata SILVER 3 12
Table:- CUSTOMER
Ccode CName VCode
1 Hemant Sahu 101
2 Raj Lal 108
3 Feroza Shah 105
4 Ketan Dhal 104
create table CABHUB (vcode integer PRIMARY KEY, VehicleName varchar(20), make
varchar(20), color varchar(20), capacity integer, charges float );
insert into cabhub values(100,'Innova','Toyota','white',7,15);
insert into cabhub values(102,'SX4','Suzuki','blue',4,14);
insert into cabhub values(104,'C Class','Mercedes','red',4,35);
insert into cabhub values(105,'A-star','Suzuki','white',3,14);
insert into cabhub values(108,'Indigo','Tata','silver',3,12);
iii) Write a query to show all records in descending order of gross salary.
Answer: select *from employee1 order by gross desc;
TABLE : PRODUCT
P_ID ProductName Manufacturer Price
TP01 Talcum Powder LAK 40
FW0 Face Wash ABC 45
5
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW1 Face Wash XYZ 95
2
ii) Write a query to show all the records in their descending order of price.
Answer: select *from product order by price desc;
iv) Write a query to add a new column “man_date” for manufacturing date.
Answer: alter table product ADD man_date date;
PYTHON PROGRAMS
Q.1. A Program to read the content of file and display the total number of consonants, vowels,
uppercase letters and lowercase letters. Show output to the examiner.
Q.2. Write a Program in Python to read & display file content line by line with each word separated
by “#” symbol. Show output to the examiner.
Q.3. A Program to generate random number 1-6, simulating a dice.
Q.4. A Program in Python which will create a stack and perform PUSH & POP operation
Q.5. A Program to connect with database and create a new table ‘student’ with following fields.
1) Admission Number 2) Student Name 3) gender and 4) marks
Q.1. A Program to read the content of file and display the total number of
consonants, vowels, uppercase letters and lowercase letters. Show output to the
examiner.
Answer:
# Program to read content of file & display total number of vowels, consonants,
lowercase and uppercase characters
f = open("abc.txt")
v=0
c=0
u=0
l=0
o=0
data = f.read()
vowels=['a','e','i','o','u']
for ch in data:
if ch.isalpha():
if ch.lower() in vowels:
v+=1
else:
c+=1
if ch.isupper():
u+=1
elif ch.islower():
l+=1
elif ch!=' ' and ch!='\n':
o+=1
print("Total Vowels in file :",v)
print("Total Consonants in file n :",c)
print("Total Capital letters in file :",u)
print("Total Small letters in file :",l)
print("Total Other than letters :",o)
f.close()
Q.2. Write a Program in Python to read & display file content line by line with each
word separated by “#” symbol. Show output to the examiner.
Answer:
#Program to read content of file line by line and display each word separated by '#'
f = open("file1.txt")
for line in f:
words = line.split()
for w in words:
print(w+'#',end='')
print()
f.close()
Q.3. A Program to generate random number 1-6, simulating a dice.
Answer:
import random
import time
print("Press CTRL+C to stop the dice ")
play='y'
while play=='y':
try:
while True:
for i in range(10):
print()
n = random.randint(1,6)
print(n,end='')
time.sleep(.00001)
except KeyboardInterrupt:
print("Your Number is :",n)
ans=input("Play More? (Y) :")
if ans.lower()!='y':
play='n'
break
Q.4. A Program in Python which will create a stack and perform PUSH & POP
operation
Answer:
mystack=[ ]
length = int(input("Enter size of stack : "))
for i in range(0,length):
n=int(input("Enter elements in stack : "))
mystack.append(n)