CLASS XI (COMPUTER SCIENCE) HALF YEARLY MS BHOPAL Region
CLASS XI (COMPUTER SCIENCE) HALF YEARLY MS BHOPAL Region
CLASS XI (COMPUTER SCIENCE) HALF YEARLY MS BHOPAL Region
At translation
— Determined by programmer — bind type to variable name, value to constant.
— Determined by translator — bind global variable to location (at load time), bind source
program to object program representation. (2)
OR
1 mark for definition and 1 mark for example
(b) Assume variable a holds 10 and variable b holds 20 then:
(c) ABC+ABC+ABC+ABC+ABC
=BC(A+A)+AB(C+C)+AB(C+C)
=BC+AB+AB
=AB+B(A+C) (3)
(d) Four functions performed by compression tools are:
(i) Reduce the file size
(ii) Provides faster access
(iii) Makes file transfer easy over web (due to small file size)
(iv) Prevents any data loss in files. (4)
4. (a) List is a data structure to store homogeneous data. Like string indices, list indices start at 0, and
lists can be sliced, concatenated and so on:
>>> a[0]
‘spam’
>>> a[3]
1234
>>> a[-2]
100
>>> a[1:-1]
[‘eggs’, 100]
>>> a[:2] + [‘bacon’, 2*2]
[‘spam’, ‘eggs’, ‘bacon’, 4]
>>> 3*a[:3] + [‘Boe!’]
[‘spam’, ‘eggs’, 100, ‘spam’, ‘eggs’, 100, ‘spam’, ‘eggs’, 100, ‘Boe!’] (2)
(b) input() is used to get string input while raw_input() is used to get integer input.
Example:
>> name=input(‘Enter a Name’)
>>age=raw_input (‘Enter Age’) (2)
(c) Python basically has three datatypes: dict, list and set
list([iterable]) : Return a list whose items are the same and in the samitems. iterable may be either a
sequence, a container that supports iteration, or an iterator object.
class dict(iterable, **kwarg)
Return a new dictionary initialized from an optional positional argument and a possibly empty set of
keyword arguments.
class set([iterable])
Return a new set or set object whose elements are taken from iterable. The elements of a set must
be hashable. To represent sets of sets, the inner sets must be frozenset objects. If iterable is not
specified, a new empty set is returned. (3)
(d) (i) math.ceil(x)
Return the ceiling of x as a float, the smallest integer value greater than or equal to x.
(ii) math.fabs(x)
Return the absolute value of x.
(iii) math.floor(x)
Return the floor of x as a float, the largest integer value less than or equal to x.
(iv) math.factorial(x)
Return x factorial. Raises ValueError if x is not integral or is negative. (4)
OR
1 mark for definition and 1 for example
ii) 1 mark for definition and 1 for example
OR
(1)
(c) Defining a Function
You can define functions to provide the required functionality. Here are simple rules to define a function
in Python:
Function blocks begin with the keyword def followed by the function name and
parentheses ( ( ) ).
Any input parameters or arguments should be placed within these parentheses. You can also
define parameters inside these parentheses.
The first statement of a function can be an optional statement - the documentation string of the
function or docstring.
The code block within every function starts with a colon (:) and is indented.
The statement return [expression] exits a function, optionally passing back an expression to the
caller. A return statement with no arguments is the same as return None.
Syntax :
def functionname( parameters ):
“function_docstring” function_suite
return [expression]
(d) x = 0
while True: try:
x = int(raw_input(‘input a decimal number \t’)) if x in
xrange(1,1000000001):
y = bin(x) rev
= y[2:]
print(“the reverse binary soln for the above is %d”) %(int(‘0b’+rev[::-1],2)) break
except ValueError:
print(“Please input an integer, that’s not an integer”)
continue (3)
(e) Name Symbol Use in flowchart
(4)
OR
A flowchart is a type of diagram that represents an algorithm, workflow or process. The flowchart shows the
steps as boxes of various kinds, and their order by connecting the boxes with arrows. This diagrammatic
representation illustrates a solution model to a given problem. Flowcharts are used in analyzing, designing,
documenting or managing a process or program in various fields.
(b) 1 mark for writing correct law and 1 mark for verifying using truth table
(2)
(c) #program to find factorial of a number
n=int(raw_input(‘Enter the number ‘)) fact =
1
while n :
fact = fact * n
n=n-1
print “Factorial of number is “,fact (2)
OR
a=int(input("Please Enter a Number : "));
if(a%2==0):
print("This Number is Even")
else:
print("This Number is Odd")