You are on page 1of 32

Topic: Review of Python Basics

Q1. WAP to print the following ASCII art using ASCII statements.

Q2. WAP to print the following pattern.

Q3. Write a program that inputs a word (as a string, of course) and
(i) Prints back the word without the vowels.
For example,
If input word is "nectarine" then output should be 'nctrn'.
If input word is "blueberry" then output should be 'blbrry'.
(ii) Surround the vowels with parentheses instead of not showing them.
For example,
If input word is "nectarine" then output should be 'n(e)ct(a)r(i)n(e)'.
If input word is "blueberry" then output should be 'bl(u)(e)b(e)rry'.
Q4. Write a program that accepts a list and removes the value at index 0 from the list.
The program must actually modify the list passed in, and not just create a second list with
the first
item removed. You may assume the list you are given, will have at least one element.
For example:
If input list is a = [1, 2, 3, 4], the output should be [2, 3, 4].
Topic: Functions
Q5. Write a void function that receives a 4 digit number and calculates the sum of squares
of first
two digits number and last two digits number,
e.g., if 1233 is passed as an argument then function should calculate 122 + 332
Q6. Write a random number generator that generates random numbers between 1 and 6.
(simulates
a dice).
Topic: Data File Handling
Q7. Read text file by line by line and display each word separated by a #.
Q8. Read a text file and display the number of vowels/ consonants/ uppercase/ lowercase
characters
in the file.
Q9. Remove all the lines that contain the character ‘a’ in a file and write it to another file.
Q10. Create a binary file with roll number, name and marks. Search for a given roll number
and
display the name, if not found display appropriate message.
Q11. Create a binary file with roll number, name and marks. Input a roll number and update
the
marks.
Q12. Create a CSV file by entering user-id and password, read and search the password for
given
User-id.
Q13. Write a menu driven program implementing user-defined functions on a CSV file
“students” to
read and display the name and percentage of the records of students.
Input admission number, name and percentage to the CSV file.
Q14. Develop a Python program which stores employee number, name and salary of
employees in
“employee.csv”, calculates and display the total salary remitted to the employees and to
display the
number of employees who are drawing a salary of more than Rs. 15,000/- per month.
Topic: Data Structures - Stack
Q15. Each node of a STACK contains the following information:
(i) Pin code of a City
(ii) Name of City
Write a program to implement the following operations in the above stack:
(a) PUSH() to push a node into the stack.
(b) POP() to remove a node from the stack.
Q16.
Topic: SQL
Q1. Write SQL query to create a database of your name.
Q2. Write a query to change the database to your name.
Q3. Create the following table and insert the below given records in the table.
TABLE: STUDENT

Q4. Select all the Nonmedical stream students from STUDENT.


Q5. List the names of those students who are in class 12 sorted by stipend.
Q6. To display name & average of all the students having avgmark <70.0.
Q7. To display list of all the students with Stipend >350.00 in ascending order of Name.
Q8. To display the Stream & the number of students in each Stream in the table Student.
Q9. List all students sorted by avgmark in descending order.
Q10. To count the number of students with grade "A".
Q11. Update the students stipend with Rs. 100.00 whose Grade is 'A'.
Q12. To display the count of students and the total stipend given stream wise.
Q13. Create the following table and insert the below given records in the table.

Q14. To display the name of students, department number, stream and the name of HOD
from the
above 2 tables.
Q15. Display name, class and stream whose department number is 3 and 4.
Q16. Display the minimum, maximum and average stipend stream wise.
Q17. Delete the record of Humanities stream from both the tables.
Q18. Modify the column size of Name to 30 of STUDENT table.
Q19. Drop the Primary key of DEPARTMENT table and then add the Primary key again.
Q20. Drop the column HOD from DEPARTMENT table.
Q21. Delete the entire DEPARTMENT table.
Topic: Python-MySQL Connectivity
Q17. Create a database TESTDB.
• Create a table EMPLOYEE with Fields FIRST_NAME, LAST_NAME, AGE, GENDER and
INCOME in
TESTDB.
• Insert 5 records through Python. Records to be inserted at the run-time.
Q18. Search for a particular record. Input record to be taken at the run-time.
• Display all the records that are available in the table.
Q19. Delete a particular record by taking the details of the record at the run-time.
Q20. Edit a particular record by taking the details of the record at the run-time.
NOTE: Display appropriate message if the record does not exist
Ryan International School, Ghaziabad
INDEX
S.N DATE TOPIC PAGE TEACHER
O NO. SIGNATURE
Topic: Review of Python Basics
Month: April
1. ASCII Art Program
2. Display the patterns
3. Input word, display without vowels,
then display with vowels surrounded
by parentheses
4 To remove the value at 0 index from a
list
Topic: Functions
Month: June
5 To calculate the sum of squares of
first two-digit and last two digit
numbers of a 4 digit number
6 To generate random numbers
between 1 and 6 (dice simulator)
Topic: Data File Handling – Text file,
Binary file and CSV file
Month: July
7 Display each word of a text file
separated by ‘#’
8 Display the number of vowels,
consonants, uppercase, lowercase
characters in the text file
9 To remove the lines that contain ‘a’ in
a file and write them to another file
10 To perform search in a binary file
11 To update marks of a particular
record in a binary file
12 Input user-id and password, and
check for the validity of login
credentials from the CSV file
13 Input admission number, name and
percentage in the CSV file. Display the
name and percentage of the records
of students from a CSV file.
14 Store employee number, name and
salary of employees in
“employee.csv”. calculate and display
the total salary remitted to the
employee and the number of
employees
drawing more than Rs. 15.000/- from
a CSV file.
Topic: Data Structures – Stack
Month: August
15 PUSH and POP operations of a stack
Topic: SQL
Month: October
16 Create a database
17 Change the database
18 Create a student table (DDL
command) and insert records (DML
commands)
19 Display records with constraints
20 Sorting the records
21 Display records with constraint (SQL
command)
22 Display records with constraint and
string
23 Grouping the records
24 Display records with constraint
25 Aggregate function
26 Update the records (DML commands)
27 Grouping the records
28 Create a department table (DDL
command) and insert records (DML
commands)
29 Combining the two tables using
foreign key (DML command)
30 Combining the two tables using
foreign key
31 Aggregate function
32 Delete records (DML command)
33 Alter the structure of a field (DDL
command)
34 Drop and add a primary key (DDL
command)
35 Drop a column (DDL command)
36 Delete the entire table (DDL
command)
Topic: Python – MySQL Connectivity
Month: November
37 Create a table and insert records
38 Search for a particular and display all
the records
39 Delete a particular record
40 Edit a particular record
1.
print('\t','',chr(46)*8)
print('\t',chr(40),chr(35)+chr(45)+chr(46)*3,chr(34)+chr(92))
print('\t','',chr(92)+chr(35),'\t','',chr(124))
print('\t','',chr(95)+chr(41)+chr(34)+chr(35)*4+chr(34)+chr(124)+chr(95))
print('\t',chr(40)+chr(95)+chr(34)+chr(35)*6+chr(34)+chr(39)+chr(95)+chr(41))
print('\t','',chr(47)+chr(96)+chr(34)*7+chr(96)+chr(92))
print('\t',chr(124),'\t',chr(111),chr(95)+chr(111)+chr(92))
print('\t',chr(124),'\t','',chr(40)+chr(95)+chr(62)+chr(124))
print('\t','',chr(92),' ',chr(39)+chr(46)+chr(95)*3+chr(47)+chr(45)*2+chr(35))
print('\t',' ',chr(39)+chr(46),' ',chr(59)+chr(45)+chr(46)+chr(95)+chr(59)+chr(39)+chr(92))
print('\t',' ',chr(41)+chr(35)*3+chr(92)+'',chr(60)+chr(62)+chr(95)+chr(47),' ',chr(95)*2)
print('
',chr(46)*4+chr(96)*2+chr(39)+chr(35)*4+chr(96)+chr(46)+chr(39)+chr(92)+chr(95)*2+chr(4
6)+chr(39),chr(96)+chr(124))
print(' ',chr(47)+'\t\t',' ',chr(40)+chr(41)+chr(92)+'\t',' ',chr(47))
print(' ',chr(92)+chr(95)*2+chr(46)*2+chr(45)*2+chr(39)+'\t','
',chr(92)+chr(95)+chr(46)+chr(45)+chr(39))
print('\t',chr(124),'\t',' ',chr(40)+chr(41),chr(124))
print('\t',chr(59),'\t\t'+chr(59))
print('\t',chr(92)+'\t '+chr(40)+chr(41)+chr(47))
print('\t ',chr(92),'\t '+chr(39)+chr(46),chr(47))
print(' ',chr(95)+chr(46)+chr(39)+chr(96)+chr(92)+'\t '+chr(96)+chr(59))
print(' ',chr(40),' ',chr(96)+chr(92),'\t ',chr(92)+chr(95))
print(' ',chr(92),' ',chr(46)+chr(45)+chr(96)+chr(92),' ',chr(96)+chr(92))
print('\t'+chr(92)+chr(95)*2+chr(41),' ',chr(96)+chr(46)+chr(95)*6+chr(46)+chr(39))

OUTPUT
2(i)
# FIRST PART
A=7
B=1
for row in range(0,9):
for col in range(0,9):
if row==0 or row==8:
print('*',end="")
elif row==B and col==A:
print('*',end="")
B+=1
A-=1
else:
print(end=" ")
print()
OUTPUT
2(ii)
# SECOND PART
n=int(input("Enter the number of rows:"))
for i in range(n,0,-1):
for j in range(1,i+1):
print('*',end=" ")
for j in range(2*(n-i)):
print(" ",end=" ")
for j in range(1,i+1):
print('*',end=" ")
print()
for i in range(n):
for j in range(i+1):
print('*',end=" ")
for j in range(2*(n-i-1)):
print(" ",end=" ")
for j in range(i+1):
print('*',end=" ")
print()
OUTPUT
3 (i) and (ii)
def str1(a):
b=''
for i in a:
if i not in 'aeiouAEIOU':
b+=i
return b
def str2(a):
for i in a:
if i not in 'aeiouAEIOU':
print(i,end='')
else:
print('(',i,')',end='')
stg=input('Enter String: ')
print(str1(stg))
str2(stg)
OUTPUT

4.
a= []
b = int(input("enter the total no of elements:"))
for i in range(b):
ele = int(input("enter the element:"))
a.append(ele)
print("the original list:",a)
a.remove(a[0])
print("the list after editing:",a)
OUTPUT

5.
num=int(input("Enter a number:"))
a=num%100
b=num//100
sum1=(b)*(b)+(a)*(a)
print(b,'^2 + ',a,'^2 =',sum1)
OUTPUT

6. def dice():
import random
a=random.randint(1,6)
if a==1:
print("-----")
print("| . |")
print("-----")
elif a==2:
print("-----")
print("|. |")
print("| .|")
print("-----")
elif a==3:
print("-----")
print("|. |")
print("| . |")
print("| .|")
print("-----")
elif a==4:
print("-----")
print("|. .|")
print("|. .|")
print("-----")
elif a==5:
print("-----")
print("|. .|")
print("| . |")
print("|. .|")
print("-----")
else:
print("-----")
print("|...|")
print("|...|")
print("-----")
dice()
OUTPUT
7.
f = open('POEM 3.txt','r')
n = f.readlines()
for i in range(len(n)):
words=n[i].split()
for j in words:
print(j,end="#")
OUTPUT

8.
f =open('POEM 3.txt', 'r')
x = f.read()
vowel = 0
consonants = 0
uppercase = 0
lowercase = 0
for i in x:
if i in 'AEIOUaeiou':
vowel+=1
else:
consonants+=1
if i.isupper():
uppercase+=1
if i.islower():
lowercase+=1
print('NUMBER OF VOWELS:',vowel)
print('NUMBER OF CONSONANTS:',consonants)
print('NUMBER OF UPPERCASE:',uppercase)
print('NUMBER OF LOWERCASE:',lowercase)
f.close()
OUTPUT

9.
F = open('POEM 3.txt','r')
f = open('POEM.txt','w')
x = F.readlines()
for i in x:
if 'A' not in i:
POEM.writelines(i)
print('YOUR FILE HAS BEEN UPDATED')
f.close()
F.close()
OUTPUT

10.
import pickle
def WRITE():
d = {}
f = open('STUDENTS.txt','wb')
while True:
r = int(input("ENTER THE ROLL NUMBER:"))
N = input('ENTER NAME:')
d['ROLL NUMBER'] = r
d['NAME'] = N
pickle.dump(d,f)
ch = input('DO YOU WANT TO CONTINUE:')
if ch in "Nn":
break
f.close()
def SEARCH():
found = 0
rollno = int(input('ENETER THE ROLL NO WHOSE NAME TO BE DISPLAY'))
f = open('STUDENTS.txt','rb')
try:
while True:
rec = pickle.load(f)
if rec['ROLL NUMBER'] == rollno:
print(rec['NAME'])
found = 1
break
except EOFError:
f.close()
if found == 0:
print('SORRY NO RECORD FOUND')
f.close()
WRITE()
SEARCH()
OUTPUT
11.
import pickle
f=open('STU','wb')
stu={}
while True:
rno=int(input("ENTER THE ROLL NO:"))
name=input("ENTER THE NAME:")
marks=eval(input("ENTER THE MARKS:"))
stu[rno]=[name,marks]
ch=input("DO YOU WANT TO CONTINUE?(Y/N)")
if ch in 'Nn':
break
pickle.dump(stu,f)
f.close()
roll=int(input("ENTER THE ROLL NO FOR UPDATING THE MARKS:"))
new=eval(input("ENTER THE NEW MARKS:"))
found=False

try:
f=open('STU','rb+')
while True:
pos=f.tell()
s=pickle.load(f)
if roll in s:
s[roll][1]=new
found=True
f.seek(pos)
pickle.dump(s,f)
f.close()
except EOFError:
if found==False:
print('SORRY')
try:
f=open('STU','rb')
while True:
s=pickle.load(f)
print('UPDATED RECORS:',s)
f.close()
except EOFError:
pass

OUTPUT
12.
import csv
f=open('record.csv','w',newline='')
data=[]
while True:
L=int(input("Enter the user id:"))
M=int(input("Enter the password:"))
data.append([L,M])
ch=input("Do you want to continue?")
if ch in 'Nn':
break
heading=['user_id','password']
f1=csv.writer(f,delimiter=',')
f1.writerow(heading)
f1.writerows(data)
f.close()
f=open('record.csv','r')
csvreader=csv.reader(f)
searchid=int(input("Enter the id you wanna search:"))
for i in csvreader:
if csvreader.line_num==1:
continue
else:
if int(i[0])==searchid:
print(i)
break
f.close()
OUTPUT

13.
import sys
import csv
students=[]
def MENU():
print("1.ADD\n2.DISPLAY\n3.EXIT")
ch=int(input("Enter your choice:"))
if ch==1:
ADD()
elif ch==2:
display()
else:
sys.exit()
def ADD():
f=open("class.csv",'w',newline="")
while True:
adno=int(input("Enter admission number:"))
name=input("Enter the name:")
percen=eval(input("Enter the percentage:"))
students.append([adno,name,percen])
ch=input("Do you want to continue?")
if ch in 'Nn':
break
heading=['admission no','name','percentage']
f1=csv.writer(f,delimiter=',')
f1.writerow(heading)
f1.writerows(students)
f.close()
MENU()

def display():
f=open('class.csv','r')
csvreader=csv.reader(f)
search=int(input("Enter the admission number you want to search:"))
for i in csvreader:
if csvreader.line_num==1:
continue
elif int(i[0])==search:
print(i)
break
f.close()
MENU()
MENU()
OUTPUT
14.
import csv
f=open('employee.csv','w',newline="")
emp=[]
con=0
sum1=0
while True:
empno=int(input("Enter the employee number:"))
name=input("Enter the employee name:")
sal=eval(input("Enter the salary:"))
emp.append([empno,name,sal])
ch=input("do you want to continue:")
if ch in 'Nn':
break
f1=csv.writer(f,delimiter=",")
f1.writerow(['emp no','name','salary'])
f1.writerows(emp)
f.close()
f=open('employee.csv','r')
csvreader=csv.reader(f)
for i in csvreader:
if csvreader.line_num==1:
continue
else:
sum1+=int(i[2])
if int(i[2])>15000:
con+=1
print('Number of employees drawing salary more than Rs.10000:',con)
print('Total salary remitted to employees Rs.',sum1)
f.close()
OUTPUT

15.
import sys
sta=[]
def MENU():
print("1.PUSH\n2.POP\n3.EXIT")
ch=int(input("Enter your choice:"))
if ch==1:
PUSH()
elif ch==2:
POP()
else:
sys.exit()
def PUSH():
pcode=int(input("Enter the pin code of city:"))
name=input("Enter the name of city:")
sta.append([pcode,name])
print(sta[len(sta)-1],'<- TOP')
for i in range(len(sta)-2,-1,-1):
print(sta[i])
MENU()
def POP():
if sta==[]:
print('underflow')
else:
a=sta.pop()
print("Deleted element=",a)
MENU()
MENU()

OUTPUT
16.
(i)

(ii)
(iii)

(iv)

(iv)
(v)

(vi)

(vii)

(viii)

(ix)
(x)

(xi)

(xii)

You might also like