0% found this document useful (0 votes)
151 views

Computer Practical File

This practical file contains 20 programs based on learning Python programming and the concept of database management with MySQL. It includes programs to print patterns, check for palindromes, create and manipulate tuples, check for prime numbers, sort dictionaries, and perform database operations like creating tables, inserting records, and using SQL commands. The file contains the code, output, and description for each program.

Uploaded by

Saad Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
151 views

Computer Practical File

This practical file contains 20 programs based on learning Python programming and the concept of database management with MySQL. It includes programs to print patterns, check for palindromes, create and manipulate tuples, check for prime numbers, sort dictionaries, and perform database operations like creating tables, inserting records, and using SQL commands. The file contains the code, output, and description for each program.

Uploaded by

Saad Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Vikalp Verma

Class XIIth
Commerce
Roll No- 65
As per CBSE Guidelines, and Syllabus
per the Academic Year 2020-21

Computer
Practical File
RPM Academy
Introduction – I

This Practical File is submitted for the


fulfillment of Subject - Information
Practices with Python & Concept
of Database Management with
MySQL.

REPORT TITLE PAGE 1


INTRODUCTION - II

Contents

This Practical File has 20 Programs based on our learning of


Programming on Python and understanding of RDBMS.

Concepts

Python Programming (version MySQL to help us understand


3.9, 64 bit) to help us the working of Relational
understand and be able to Database models and create
formulate algorithms and Databases and Tables of
provide detailed programs organizations.
along with its output.

REPORT TITLE PAGE 2


CERTIFICATE
THIS IS TO CERTIFY THAT HE/SHE HAS WORKED
UNDER MY SUPERVISION AND COMPLETED IT TO MY
FULL SATISFACTION.

TEACHER NAME: -

TEACHER SIGNATURE: -

DATE: -

REPORT TITLE PAGE 3


ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude
to my teacher (Sneha Mam) who gave me the golden
opportunity to do this wonderful project on the topic
(Programming coding in Python.) which also helped
me in doing a lot of Research and I came to know
about so many new things I am really thankful to
them.
Secondly I would also like to thank my parents and
friends who helped me a lot in finalizing this project
within the limited time frame.

REPORT TITLE PAGE 4


REPORT TITLE PAGE 5
Program/Question List

Q:-1- Write a program to print the following pattern :-


(A)
********
           *
        *
      *
    *
 *
********
(B)
**********
****   ****
***      ***
**         **
*            *
*            *
**         **
***      ***
****   ****
Q :-2= Write python that create a tuple storing first 9 term of Fibonacci series .
Q.:-3-A program that reads a string and checks whether it is a palindrome string or not.
Q:-4-Write a program to accept values from a user in a tuple. Add a tuple to it and display its elements
one by one. Also display its maximum and minimum value.
Q:-5- = Write a function that takes one argument and report if the argument is prime or not . write a
program that invokes this function .
Q:-6 = Write a void function that receives a 4 digit number and calculate the sum of the square of first 2
digits number and last digits number .
Q:-7-Write a Python program to sort a dictionary by key.
Q:-8-Write a program to increase salary of the employee, whose name is "MANOJ KUMAR", by 3000.
Q:-9-Create a database TESTDB.

• Create a table EMPLOYEE with Fields FIRST_NAME, LAST_NAME, AGE, SEX and INCOME in
TESTDB.
Q:10- = Consider the file “SarojiniPoem.txt”

Autumn Song

Like a joy on the heart of a sorrow,


The sunset hangs on a cloud;
A golden storm of glittering sheaves,
Of fair and frail and fluttering leaves,
The wild wind blows in a cloud.

REPORT TITLE PAGE 6


Hark to a voice that is calling
To my heart in the voice of the wind:
My heart is weary and sad and alone,
For its dreams like the fluttering leaves have gone,
And why should I stay behind?

Sarojini Naidu

Based on the above file, answer the following question:


 
(a) What would be the output of following code?

file = open ("sarojiniPoem.txt","r")


text = file.readlines()
file.close()
for line in text  :
    print (line , end = ' ' )
print ( )

(b) Modify the program so that the lines are printed in reverse order.

(c) Modify the code so as to output to another file instead of the screen. Let your script overwrite the
output file.

(d)Change the script of part (c) that it append output to an existing file.

(e) Modify the program so that each line is printed with a line number at beginning.
• Create a table EMPLOYEE with Fields FIRST_NAME, LAST_NAME, AGE, SEX and INCOME in
TESTDB.

Q:-11-Write a Python database connectivity script that deletes records from category table of database
items that have name = 'Stockable'
Q;-12- Design a Python application that fetches all the records from Pet table of menagerie database.
Q:-13- Read a text file by line by line and display each word separated by #.
Q:-14-Read a text file and display the number of vowels / consonants/ uppercase/ lowercase characters in
the file.
Q:-15-Write a random number generator that generates random numbers between 1 to 6.
Q:-16-Write a Python program to implement a stack and queue using a list data-structure.
Q-17- Create a binary file with rollno , name , and marks. Input the roll number and update the marks.
Q:-18- Create a binary file with name, and roll no. Search for a given roll no and display the name , If not
found display appropriate message.
Q:-19-Write a python program to sort a dictionary by key.
Q:-20-DATABASE MANAGEMENT
->Create a student table and insert data. Implement the following SQL commands on the student table.
ALTER table to add new attributes / modify data type / drop attribute
UPDATE table to modify data.
ORDER BY to display data in ascending /descending order
DELETE to remove tuple(s)

REPORT TITLE PAGE 7


GROUP By and find the min , max , sum , ,count , and average.

Program # 1
CODE:

a="";
for row in range(0,7):
for column in range(0,7):
if (((row == 0 or row == 6) and column >= 0 and column <= 6) or row+column==6):
a=a+"*"
else:
a=a+" "
a=a+"\n"
print(a);

OUTPUT:

Program # 1.b

CODE :
n=int(input("enter the number of nows : "))
for i in range (n, 0, -1):
for j in range (i, 0, -1):
print('*', end=' ')

for j in range (2*(n-i)):


print(' ', end=' ')

for j in range (i, 0, -1):


print('*', end=' ')

print()

for i in range (n):


for j in range (i+1):

REPORT TITLE PAGE 8


print('*', end=' ')

for j in range (2*(n-i-1)):


print(' ', end=' ')

for j in range (i+1):


print('*', end=' ')

print()

OUTPUT :

PROGRAM # 2
CODE:
a = (0,1,1)
for i in range(6):
a = a + ( a [ i +1] + a [ i + 2 ] ,)
print(a)

OUTPUT:

REPORT TITLE PAGE 9


PROGRAM # 3
CODE:
def palstr(s):
return s == s[::-1]

s = input(str("Enter a word : "))


ans = palstr(s)

if ans:
print("The word is a Palindrome !")
else:
print("No, the given is not a palindrome !")

OUTPUT:

PROGRAM # 4
CODE:
t=tuple( )
n=int(input("Number of Units you want in your tuple : "))

for i in range(n):
a=input("Enter numbers you want to add: ")
t+=(a,)

print('The Tuple formed is as follows : ' ,t)

for i in t:
print('The Element Tuples are : ', i)

print("MAXIMUM VALUE OF THE TUPLE IS : ", max(t))


print('MINIMUM VALUE OF THE TUPLE IS : ', min(t))

OUTPUT:

REPORT TITLE PAGE 10


PROGRAM #5
CODE:
num=int(input("Enter a Number : "))

if num > 1:
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
break
else:
print(num,"is a prime number")

else:
print(num,"is not a prime number")

OUTPUT:

REPORT TITLE PAGE 11


PROGRAM # 7
CODE:
day_dict = {'Monday':'#1',
'Tuesday':'#2',
'Wednesday':'#3',
'Thursday':'#4',
'Friday':'#5',
'Saturday':'#6',
'Sunday':'#7'}
month_dict = {'1':'January','2':'February','3':'March'}

print("First Dict sorted : ")


for key in sorted(day_dict):
print(key, day_dict[key])

print("Second Dict sorted : ")


for key in sorted(month_dict):
print(key, month_dict[key])

REPORT TITLE PAGE 12


PROGRAM #10 (POEM)
a)

b)

REPORT TITLE PAGE 13


C)

D)

E)

REPORT TITLE PAGE 14


PROGRAM # 13

CODE:
file=open("sample.txt","r")

doc=file.readlines()

for i in doc:
words=i.split()
for a in words:
print(a+"#")
print("")
file.close()

OUTPUT:

PROJECT # 14
CODE:
infile = open("Sample.txt", "r")

REPORT TITLE PAGE 15


vowels = set("AEIOUaeiou")
cons = set("bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ")

countV = 0
countC = 0
for c in infile.read():
if c in vowels:
countV += 1
elif c in cons:
countC += 1

print("The number of Vowels is: ",countV,"\nThe number of consonants is: ",countC)

OUTPUT:

PROJECT #15
CODE:
import random

print ("A Random Number between 1 to 6 is : ", random.randint(1, 6))

OUTPUT:

PROJECT # 16
CODE:

REPORT TITLE PAGE 16


REPORT TITLE PAGE 17

You might also like