Preboard 11
Preboard 11
2.After practicals, Atharv left the computer laboratory but forgot to sign off
from his email account. Later, his classmate Revaan started using the
same computer. He is now logged in as Atharv. He sends inflammatory
email messages to few of his classmates using Atharv’s email account.
Revaan’s activity is an example of which of the following cyber crime?
a. Hacking b. Identity theft c. Cyber bullying d.
Plagiarism
7. Write a function in Python that displays the words, starting with uppercase
letter in a file ‘legend.txt’.
Example: If the “legend.txt” contents are as follows:
Diego Maradona, Argentinian soccer legend and celebrated Hand of
Godscorer dies at 60.
The output of the function should be:
Diego Maradona, ArgentinianHand God
14. Write a user defined function in python SHIFT(lst) that would accept a list as
argument .The function should shift the negative numbers of the list to right
and the positive numbers to left without using a another list.
For example if list initially contains
[3, -5, 1, 3, 7, 0, -15, 3, -7, -8]
Then after shifting list should contain
[3, 1, 3, 7, 0, 3, -8, -7, -15, -5]
{" Gift_ID ":value, " Name ":value, " Remarks ":value, " Price ":value}
Write a function BUMPER() in Python to read each record of a binary file
GIFTS.DAT, find and display details of those gifts, which has remarks as
"ON DISCOUNT".
ii. Write a function TRANSFER( ) in python, that would copy all
those records which are having price greater than 500 to
G_COPY.DAT .
18. Assertion (A): In the case of positional arguments, the function call and
function definition statements match in terms of the number
and order of arguments.
Reasoning (R): During a function call, positional arguments should precede
keyword arguments in the argument list.
19. Assertion (A): A SELECT command in SQL can have both WHERE and
HAVING clauses.
Reasoning (R): WHERE and HAVING clauses are used to check
conditions, therefore, these can be used interchangeably.
20. Write a Python program to input an integer and display all its prime factors in
descending order, using a stack. For example, if the input number is 2100, the
output should be: 7 5 5 3 2 2 (because prime factorization of 2100 is
7x5x5x3x2x2)
Hint: Smallest factor, other than 1, of any integer is guaranteed to be prime.
22. csv file "Happiness.csv" contains the data of a survey. Each record of
the file contains the following data:
● Name of a country
● Population of the country
● Sample Size (Number of persons who participated in the survey in
that country)
● Happy (Number of persons who accepted that they were Happy)
For example, a sample record of the file may be:
Signiland, 5673000, 5000, 3426
Write the following Python functions to perform the specified operations
on this file:
(I) Read all the data from the file and display all those records for
which the population is more than 5000000.
(II) Count the number of records in the file.
27. Which block lets you test a block of code for errors?
A. try
B. except
C. finally
D. None of the above
29. Assertion(A): If the arguments in a function call match the number and order of
argumets as defined in the function definition,such arguments are called the
positional
arguments.
Reasoning(R): During a function call,the argument list first contains default
arguments
followed by positional arguments.
30. Assertion(A): The random module is a built-in module to generate the pseudo-
random
variables.
Reason(R): The randrange() function is used to generate a random number between the
specified range in its parameter.
31. Assertion (A): Global variable is declared outside the all the functions.
Reasoning (R): It is accessible through out all the functions.
32. Assertion (A): The math.pow(2,4)gives the output: 16.0
Reason (R): The math.pow() method receives two float arguments, raise the first to
the
second and return the result.
33. Assertion (A): Built-in function are predefined in the language that are used
directly.
Reason (R): print() and input() are built-in functions
34. Assertion (A):- In Python, statement return [expression] exits a function.
Reasoning (R):- Return statement passes back an expression to the caller.
A return statement with no arguments is the same as return None.
35. Assertion (A): When passing a mutable sequence as an argument, function
modifies
the original copy of the sequence.
Reasoning (R): Function can alter mutable sequences passes to it.
37. .Assertion(A):After adding element in a list, its memory location remains same
Reason(R):List is a mutable data type
41. What possible output(s) are expected to be displayed on screen at the time of
execution of the following code? Also specify the maximum and minimum value that
can be assigned to variable X.
import random
L=[10,7,21]
X=random.randint(1,2)
for i in range(X):
Y=random.randint(1,X)
print(L[Y],"$",end=" ")
(i)10 $ 7 $ (ii) 21 $ 7 $ (iii) 21 $ 10 $ (iv) 7 $
42. Statement1: Local Variables are accessible only within a function or block in
which it
is declared.
Statement2: Global variables are accessible in the whole program
44. Which of the following python statement will bring the read pointer to 10th
character from the
end of a file containing 100 characters, opened for reading in binary mode.
a) File.seek(10,0) b) File.seek(-10,2) c) File.seek(-10,1) d) File.seek(10,2)
45. Vedansh is a Python programmer working in a school. For the Annual Sports
Event, he has
created a csv file named Result.csv, to store the results of students in different
sports events. The
structure of Result.csv is : [St_Id, St_Name, Game_Name, Result]
Where
St_Id is Student ID (integer)
ST_name is Student Name (string)
Game_Name is name of game in which student is participating(string)
Result is result of the game whose value can be either 'Won', 'Lost' or 'Tie'
For efficiently maintaining data of the event, Vedansh wants to write the following
user defined
functions:
Accept() – to accept a record from the user and add it to the file Result.csv. The
column headings
should also be added on top of the csv file.
wonCount() – to count the number of students who have won any event.
As a Python expert, help him complete the task.
46. Kiran is a Python programmer working in a shop. For the employee’s tax
collection, he has
created a csv file named protax.csv, to store the details of professional tax paid
by the employees.
The structure of protax.csv is : [empid, ename, designation, taxpaid]
Where,
empid is employee id (integer)
ename is employee name (string)
designation is employee designation(string)
taxpaid is the amount of professional tax paid by the employee(string)
For efficiently maintaining data of the tax, Kiran wants to write the following
user defined
functions:
Collection() – to accept a record from the employee and add it to the file
protax.csv.
Totaltax() – to calculate and return the total tax collected from all the
employees.
As a Python expert, help him complete the task
47. Assertion(A): The resultset refers to a logical set of records that are fetched
from the
database executing an SQL Query.
Reason (R): Resultset stored in a cursor object can be extracted by using fetch(…)
functions.
49. Assertion(A): Primary key is a set of one or more attributes that identify
tuples in a
relation.
Reason (R): The primary key constraint is a combination of the NOT NULL and UNIQUE
constraints
50. Assertion(A): Foreign key is a non-key attribute whose value is derived from
primary
key of another table.
Reason (R): Each foreign key refers a candidate key in a relation
51. Assertion(A): The SELECT statement in SQL is used to retrieve data from one or
more
tables.
Reason(R): The SELECT statement can be used to retrieve all columns or a subset of
columns from a table.
52. Assertion(A): The WHERE clause in SQL is used to filter data based on a
specified
condition.
Reason(R): The WHERE clause is always required when using the SELECT statement
in SQL
53. Assertion (A): The ORDER BY clause in SQL is used to sort the result set in
ascending
or descending order.
Reason(R): The ORDER BY clause can only be used with the SELECT statement in
SQL
54. Assertion (A): The IN operator in SQL is used to match a value with a list of
values.
Reason(R): The IN operator can only be used with the where clause in SQL
55. Assertion (A): The between operator in SQL is used to match a value with in a
range of
values.
Reason(R): The between operator can only be used with numerical values in SQL.
56. Assertion (A): The LIKE operator in SQL is used to match a value with a
pattern.
Reason(R): The % and _ wildcard characters can be used with the LIKE operator in
SQL
56. Write a python connectivity program to delete the record from a table named
employee
using parameterised query and also count the number of deleted record. If the
details are
not existing,then print “Record Not Found” message?
57. Shyam has created a table named ‘Student’ in MYSQL database, ‘SCHOOL’:
• rno(Roll number )- integer
• name(Name) - string
• Per(Percentage) – float
Note the following to establish connectivity between Python and MySQL:
•Username - root • Password - manager • Host – localhost
120 | K V S E K M , P A R T – A S T U D E N T S U P P O R T M A T E R I A L , X I I
C S
Shyam, now wants to increase the percentage of students by 2% ,who got less than 40
percentage. Help Shyam to write the program in Python
59. Assertion (A):- If the arguments in a function call statement match the
number and order of arguments as defined in the function definition, such
arguments arecalled positional arguments.
Reasoning (R):- During a function call, the argument list first contains
defaultargument(s) followed by positional argument(s).
61. Ms. Shalu has just created a table named “Staff” containing Columns Sname,
Department and Salary.
After creating the table, she realized that she has forgotten to add a primary key
in the table. Help her in writing an SQL command to add a primary key - StaffId
of integer type to the table Staff.
Thereafter, write the command to insert the following record in the table:
StaffId - 111
Sname- Shalu
Department: Marketing
Salary: 45000
62. Kiran is working in a database named SCHOOL, in which he has created a table
named “STUDENT” containing columns UID, SName, Gender and Category.
After creating the table, he realized that the attribute, Category has to be
deleted
from the table and a new attribute Stream of data type string has to be added.
This attribute Stream cannot be left blank. Help him to write the commands to
complete both the tasks.
63. Write a Program in Python that defines and calls the following user defined
functions:
a) add() – To accept and add data of an employee to a CSV file
‘furdata.csv’. Each record consists of a list with field elements as fid,
fname and fprice to store furniture id, furniture name and furniture
price respectively.
b) search()- To display the records of the furniture whose price is more
than 10000.
64. Define the term Domain with respect to RDBMS. Give one example to support
your answer.
Sunil wants to write a program in Python to read a record from the table named
student and displays only those records who have marks between 80 and 95:
RollNo – integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:
∙ Username is root
∙ Password is tiger
The table exists in a MYSQL database named vidyalaya.
65. Write a program to insert the following record in the table Student:
RollNo – integer
Name – string
Class – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is abcd
The table exists in a MYSQL database named XIICS.
The details (RollNo, Name, Class and Marks) are to be accepted from the user
66. The Python interpreter handles logical errors during code execution
67.
68.