0% found this document useful (0 votes)
23 views35 pages

CS PRACTICAL FILE

Uploaded by

panthernyx16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views35 pages

CS PRACTICAL FILE

Uploaded by

panthernyx16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

CS PRACTICAL FILE

NAME :- Nyx Charkhwal


CLASS & SECTION :- 12-B
ROLL NUMBER :- 23
PYTHON QUESTION
Ques 1. Write a program using a user defined function
calcFact() to calculate and display the factorial of a
number num passed as an argument.
Answer:

Output:
Ques 2. Write a program using a user defined function
myMean() to calculate the mean of floating values
stored in a list.
Answer:

Output:

Ques 3. Write a program using a user defined function


that accepts an integer and increments the value by 5.
Also display the id of argument (before function call), id
of parameter before increment and after increment.

Answer:
Output:

Ques 4. Write a program using a user defined function


that displays the sum of first n natural numbers, where
n is passed as an argument.
Answer:

Output:
Ques 5. The company performs the following tasks to
fix the selling price of each tent.
1. Accept user requirements for the tent, such as
a) height
b) radius
c) slant height of the conical part
2. Calculate the area of the canvas used
3. Calculate the cost of the canvas used for making the
tent
4. Calculate the net payable amount by the customer
that is inclusive of the 18% tax. Write separate user
defined functions for part 2,3 and 4.
Ans:

Output:

Ques 6. Write a program that simulates a traffic light.


The program should consist of the following:
1. A user defined function trafficLight( ) that accepts
input from the user, displays an error message if the
user enters anything other than RED, YELLOW, and
GREEN.
Function light() is called and following is displayed
depending upon return value from light().
a) “STOP, your life is precious” if the value returned by
light() is 0.
b) “Please WAIT, till the light is Green“ if the value
returned by light() is 1
c) “GO! Thank you for being patient” if the value
returned by light() is 2.
2. A user defined function light() that accepts a string
as input and returns 0 when the input is RED, 1 when
the input is YELLOW and 2 when the input is GREEN.
The input should be passed as an argument.
3. Display “SPEED THRILLS BUT KILLS” after the
function trafficLight( ) is executed.
Answer:

Output:
Ques 7. Create a user defined module basic_math that contains the
following user defined functions:
1. To add two numbers and return their sum.
2. To subtract two numbers and return their difference.
3. To multiply two numbers and return their product.
4. To divide two numbers and return their quotient and print
“Division by Zero” error if the denominator is zero.
Also add a docstring to describe the module. After creating the
module, import and execute functions at shell prompt.
Answer:

Output:

Ques 8. Write a function DISPLAYWORDS() in Python to


read lines from a text file ‘Story.txt’ and display those
words, which are less than 4 characters.
Ans:
Ques 9. Write a function in Python to read a text file
line by line and display each word separated by #.

Ans:

Ques 10. Write a function in Python to read a text file


and display the number of vowels/ consonants/
uppercase / lowercase characters in a file.

Ans:
Ques 11. Write a program in python to Reverse and
display each line of text.
Ans:

Ques 12. Write a program in python to display lines of


text ending with ‘Y’ or ‘y’.
Ans:

Ques 13. Write a function in Python to read a text file


and convert the uppercase letter into lowercase and
vice versa.
Ans:

Ques 14. Write a function in PYTHON to search for a BookNo


from a binary file “BOOK.DAT”, after creating the binary
containing the records of the following
type: {BookNo":value, "Book_name":value}
The BookNo is an integer.
Ans:

Ques 15. Assuming that a binary file VINTAGE.DAT contains


records of the following type, {VNO, VDesc, price} write a
function in PYTHON to read the data VINTAGE.DAT and
display those vintage vehicles, which are priced between
200000 and 250000.
Ans:

Ques 16. Write a function in Python to search for a laptop


from a binary file “laptop.dat” containing records of following
type [ ModelNo, RAM, HDD, Details] Where ModelNo, RAM,
HDD are integers and Details is a string.The user should enter
the model number and the function should display the details
of the laptop.
Ans:

Ques 17. Write a function in Python to search for the details


of those mobile phones which have more than 1000 calls
from a binary file “mobile.dat”. Assume that binary file
contains records of the following type: (Number, Calls)
Ans:

Ques 18. Write a function in Python to read each record of a


binary file “items.dat”, find and display those items which
cost less than 2500. Assume that the file is created with
the help of objects of the following type:
{ ID:string, GIFT:string, Cost:integer}
Ans:

Ques 19. Write a function bumper() in Python to read each


object of a binary file “gifts.dat”, find and display details of
those gifts, which have remarks as “on discount”. Assume the
file is created with the help of lists of following type:
[ID, Gift, Remarks, Price]
Ans:

Ques 20. A CSV file TEACHER.CSV has following data:


TCODE,TNAME,SUBJECT,DESIG,NOP
1001,ADITI JAIN,PHYS,HOD,20
Write an interactive menu driven to do the following (using
CSV module):
● Append following records(lines) in the file TEACHER.CSV
1011,MANOJ KUMAR,ENG,PGT,24
1012,NAMITA KAUR,ENG,TGT,28
1013,PRATAP SHINDE,ENG,TGT,29
1014,GUARI KAPOOR,ENG,PRT,30
1015,HITESH DESAI,MATH,HOD,20
1016,RAKESH YADAV,MATH,PGT,26
1017,ISHITA DASH,MATH,TGT,29
1018,DILIP MATHUR,MATH,TGT,27
1019,NUPUR CHACKO,MATH,PRT,30
1020,MANAS KHER,PHYS,PRT,30
● Read and display the CSV file; at the end display number of
records(lines) present in the file
● Read the CSV file and display details if DESIG is HOD; at the
end display number of such records (lines) found in the file
● Read the CSV file and display details if DESIG is PGT and
SUBJECT is either PHYS or CHEM; if no record found in the
CSV file then display a message 'Record not found in the file'
● Exit from the menu and quit the program
Ans
Ques 21. A CSV file TEACHER.CSV has following data:
CODE,NAME,SUBJECT,DESIG,NOP
1001,ADITI JAIN,PHYS,HOD,20
Write an interactive menu driven to do the following (using
CSV module):
● Read the CSV file and display details of teachers whose
DESIG is either TGT or PGT and SUBJECT is ENG; if no record is
found then display a message 'Record not found in the file'
● Read the CSV file and display details if DESIG is either PRT
or TGT; at the end display number of such records found in
the file
● Exit from the menu and quit the program
Ans:

Ques 22. Write a function in Python that reverses a string


using Stack data structures.
Ans:

Ques 23. Write functions AddPlayer(player) and


DeletePlayer(player) in python to add and remove a player by
considering them as push and pop operations in a stack
Ans:

Ques 24. Monika has created a dictionary containing names


and marks as key-value pairs of 5 students.
Write a program, with separate user-defined functions to
perform the following operations:
1. Push the keys (name of the student) of the dictionary into
a stack, where the corresponding value
(marks) is greater than 70.
2. Pop the content of the stack
3. Display the content of the stack.
Ans:
SQL QUESTIONS
Q-1 Write SQL Command for (a) to (o) and output of (p)

TABLE : GRADUATE

S.NO NAME STIPEND SUBJECT AVERAGE DIVISION

1 KARAN 400 PHYSICS 68 I

2 DIWAKAR 450 COMP Sc 68 I

3 DIVYA 300 CHEMISTRY 62 I

4 REKHA 350 PHYSICS 63 I

5 ARJUN 500 MATHS 70 I

6 SABINA 400 CHEMISTRY 55 II

7 JOHN 250 PHYSICS 64 I

8 ROBERT 450 MATHS 68 I

9 RUBINA 500 COMP Sc 62 I

10 VIKAS 400 MATHS 57 II

a. Create Database DB1 and Create Table Graduate in DB1 database.


b. Insert 10 rows in Graduate table.

c. List the names of those students who have obtained DIV I.

D.
e. Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year
assuming that the STIPEND is paid every month.

f. To display students details who are studying maths.


g. To insert a new 11th row in the GRADUATE table:(11,”KAJOL”, 300, “Comp Sc”, 75, 1) h.

i. Add a new column GRADE of character type.

j. Display Name and division only in Graduate table.


k. To display students details sorted by NAME.

l. To display students details sorted by NAME in descending order.


m. To display student’s details whose average is between 50 to 60.

n. Display student RUBINA’s details.

O. Delete KAJOL’s details from table.


P. To display students details who are either PHYSICS or COMPUTER SC graduates.

q. Give the output of following sql statement based on table GRADUATE:

(i) Select * from GRADUATE where SUBJECT=”PHYSICS”;

(ii) Select Name, Average from GRADUATE WHERE div=2;

(iii) Select from Name, , Average from GRADUATE where AVERAGE>=65;

(iv) Select distinct SUBJECT from GRADUATE;

Q2.Consider a database LOANS with the following table:

Table: Loan_Accounts
Write SQL commands for the tasks 1 to 35

Create Database and use it

1. Create the database LOANS.

2. Use the database LOANS.

Create Table / Insert Into

3. Create the table Loan_Accounts and insert tuples in it.

4. Display the details of all the loans.

5. Display the AccNo, Cust_Name, and Loan_Amount of all the loans.


6. Display the details of all the loans with less than 40 instalments.

7. Display the AccNo and Loan_Amount of all the loans started before 01-04-2009.

8. Display the Int_Rate of all the loans started after 01-04-2009.

9. Display the details of all the loans whose rate of interest is NULL.
10. Display the details of all the loans whose rate of interest is not NULL.

11. Display the amounts of various loans from the table Loan_Accounts. A loan amount

12. Display the number of instalments of various loans from the table Loan_Accounts. An
instalment should appear only once.

13. Display the details of all the loans started after 31-12-2008 for which the number of
instalments are more than 36.

14. Display the Cust_Name and Loan_Amount for all the loans which do not have number of

instalments 36.
15. Display the Cust_Name and Loan_Amount for all the loans for which the loan amount is less
than 500000 or int_rate is more than 12.

16. Display the details of all the loans which started in the year 2009.

17. Display the details of all the loans whose Loan_Amount is in the range 400000 to 500000.

18. Display the details of all the loans whose rate of interest is in the range 11% to 12%.

19. Display the Cust_Name and Loan_Amount for all the loans for which the number of
instalments are 24, 36, or 48. (Using IN operator).
20. Display the details of all the loans whose Loan_Amount is in the range 400000 to 500000.
(Using BETWEEN operator).

21. Display the details of all the loans whose rate of interest is in the range 11% to 12%.(Using
BETWEEN operator).

22. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name
ends with ‘Sharma’.

23. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name
ends with ‘a’.

24. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name
contains ‘a’.
25. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name
does not contain ‘P’.

26. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name
contains ‘a’as the second last character.

27. Display the details of all the loans in the ascending order of their Loan_Amount.

28. Display the details of all the loans in the descending order of their Start_Date.
29. Display the details of all the loans in the ascending order of their Loan_Amount and within
Loan_Amount in the descending order of their Start_Date.

30. Put the interest rate 11.50% for all the loans for which interest rate is NULL.

31. Increase the interest rate by 0.5% for all the loans for which the loan amount is more than
400000.

32. For each loan compute Interest as (Loan_Amount*(Int_Rate/100)*Instalments).

33. Delete the records of all the loans whose start date is before 2007.

34. Delete the records of all the loans of ‘K.P. Jain’

35. Add another column Category of type CHAR(1) in the Loan table.
Q3. Create Database Work and activate it.

Create the table WORKER and add records as shown below. Write SQL

commands for the statements (a) to (g).

a. To display the details in ascending order of salary.

b. To display empno, empname in descending order of hiredate.


c. To display the details in ascending order of empno.

d. To display the sum of salary with heading ‘Sum of salary’.

e. To display the number of employees in each department number.

f. To display the number of employees in each department but number of employees should be
less than 3.
g. To display the sum of salary, average of salary, maximum and minimum salary of

each job title.

Q4.Create a table EMPLOYEE with the following data in Work database.

a. To display the list of all employees in ascending order of salary.

b. To display the employee names in descending order of age.


c. To display the grade and number of employees in each grade.

d. To display the area and number of employees in each area.

e. To display the sum and average salary of the employees of grade ‘B’.

f. To display grade and maximum, minimum and average salary of each grade.
g. To display the sum, average, maximum and minimum of salary.

h. To display grade and the number of employees in each grade where the number of employees
are more than two.

You might also like