www Padasalai Net www TrbTnpsc com COMPUTER SCIENCE PRACTICAL PROGRAMS WITH SOLUTION Practical Hand Book General Instructions 1 Eight Exercises from Python and Two from MySQL are practiced in the practical classes 2 In Practical exams the question paper will have two questions with internal choice 3 One question should be chosen from the list of internal choice 4 Distribution of Marks as follows Duration of Practical 2 Hrs Maximum Marks 20 I Internal Assessment 5 Marks II External Assessment 15 Marks Record Book Writing Code Execution 5 Marks 10 Marks 5 Marks Total 20 Marks 1 www Padasalai Net www TrbTnpsc com Sl No Question Number Page Number INDEX Program Name 1 2 3 4 5 6 7 8 9 PY1 PY2 PY3 PY4 PY5 DB6 DB7 PY8 PY9 a Calculate Factorial b Sum of Series a Odd or Even b Reverse the String Generate values and remove odd numbers Generate Prime numbers and Set Operations Display a String elements Using Class MySQL Employee Table MySQL Student Table Python with CSV Python with SQL 10 PY10 Python Graphics with Pip 3 4 5 6 7 9 12 16 18 20 2 www Padasalai Net www TrbTnpsc com PY1 a Calculate Factorial 1 a Write a program to calculate the factorial of the given number using for loop PY1 b Sum of Series 1 b Write a program to sum the series 1 1 22 2 33 3 nn n Coding fact 1 num int input Enter a Number if num 0 fact 1 for i in range 1 num1 print Factorial of num is fact fact fact i Output Enter a Number 12 Factorial of 12 is 479001600 Coding n int input Enter a value of n s 0 0 for i in range 1 n 1 print The sum of the series is s a float i i i s s a Output Enter a value of n 4 The sum of the series is 76 0 3 www Padasalai Net www TrbTnpsc com PY2 a Odd or Even 2 a Write a program using functions to check whether a number is even or odd Coding return 0 defoddeven a if a0 2 return 1 else num int input Enter a number if oddeven num 1 elif oddeven num 0 print The given number is Odd print The given number is Even Output Enter a number 7 The given number is Odd The given number is Even Enter a number 6 PY2 b Reverse the String 2 b Write a program to create a mirror of the given string For example wel lew Coding def rev str1 str2 i len str1 1 while i 0 word input n Enter a String print n The Mirror image of the given string is rev word return str2 str 2 str1 i i 1 Output Enter a String school The Mirror image of the given string is loohcs 4 www Padasalai Net www TrbTnpsc com PY3 Generate values and remove odd numbers 3 a Write a program to generate values from 1 to 10 and then remove all the odd numbers from the list Coding num1 for i in range 1 11 num1 append i print Numbers from 1 to 10 n num1 for j i in enumerate num1 print The values after removed odd numbers n num1 if i1 2 del num1 j Output Numbers from 1 to 10 10 9 8 7 6 5 4 3 2 1 The values after removed odd numbers 10 8 6 4 2 5 www Padasalai Net www TrbTnpsc com PY4 Generate Prime numbers and Set Operations 4 Write a Program that generate a set of prime numbers and another set of odd numbers Display the result of union intersection difference and symmetric difference operations Coding j 2 f 0 odd set x 1 2 for x in range 0 5 primes set for i in range 2 10 while j i 2 ifi j 0 f 1 j 1 if f 0 print Odd Numbers odd print Prime Numbers primes print Union odd union primes print Intersection odd intersection primes print Difference odd difference primes print Symmetric Difference odd symmetric difference primes primes add i Output Odd Numbers 9 7 5 3 1 Prime Numbers 7 5 4 3 2 Union 9 7 5 4 3 2 1 Difference 9 1 Intersection 7 5 3 Symmetric Difference 9 4 2 1 6 www Padasalai Net www TrbTnpsc com PY5 Display sting elements Using Class 5 Write a program to accept a string and print the number of uppercase lowercase vowels consonants and spaces in the given string using Class self string str input Enter a String Coding class String def init self self uppercase 0 self lowercase 0 self vowels 0 self consonants 0 self spaces 0 self string def getstr self def count upper self for ch in self string if ch isupper self uppercase 1 def count lower self for ch in self string if ch islower self lowercase 1 def count vowels self for ch in self string if ch in A a e E i I o O l L self vowels 1 def count consonants self for ch in self string if ch not in A a e E i I o O l L self consonants 1 def count space self for ch in self string if ch 7 www Padasalai Net www TrbTnpsc com self spaces 1 def execute self self count upper self count lower self count vowels self count consonants self count space def display self print d Spaces self spaces print The given string contains print d Uppercase letters self uppercase print d Lowercase letters self lowercase print d Vowels self vowels print d Consonants self consonants S String S getstr S execute S display Output Enter a String Welcome to Computer Science The given string contains 3 Uppercase letters 21 Lowercase letters 10 Vowels 17 Consonants 3 Spaces 8 www Padasalai Net www TrbTnpsc com DB6 MySQL Employee Table 6 Create an Employee Table with the fields Empno Empname Desig Dept Age and Place Enter five records into the table Add two more records to the table Modify the table structure by adding one more field namely date of joining Check for Null value in doj of any record List the employees who joined after 2018 01 01 SQL Queries and Output i Creating Table Employee mysql Create table Employee Empno integer 4 primary key Empname varchar 20 Desig varchar 10 Dept varchar 10 Age integer 2 Place varchar 10 ii View Table Structure mysql Desc Employee Type int 4 Field Empno Empname varchar 20 YES varchar 10 YES Desig varchar 10 YES Dept Age int 2 YES varchar 10 YES Place Null Key Default Extra NO PRI NULL NULL NULL NULL NULL NULL 6 rows in set 0 00 sec iii Inserting Data into Table mysql Insert into employee values 1221 Sidharth Officer Accounts 45 Salem mysql Insert into employee values 1222 Naveen Manager Admin 32 Erode mysql Insert into employee values 1223 Ramesh Clerk Accounts 33 Ambathur mysql Insert into employee values 1224 Abinaya Manager Admin 28 Anna Nagar …
View Full Document