C.S CH 2 &3 Preeti Arora Exercises PDF
C.S CH 2 &3 Preeti Arora Exercises PDF
C.S CH 2 &3 Preeti Arora Exercises PDF
operators
Gates use the binary
Logic
known as
number is also
. . .
(b) Base of a
of. .
.. symbols.
system is composed
(c) The decimal code which is used in computers to
the most widely used alphanumeric
code is
(d)
. .
system that
() A number
universal gates.
NAND and
NOR are called
(K)
Choice Questions
(MCQs):
3. Multiple
information?
What is
(a)
(i) Processed data
Collection of programs
(i) instructions
Collection of
(ii)
None of these
(iv)
number system? (iv) 16
What is the base
of binary
(b) (ii) 2
(i) 8 in) 10
number system? (iv) 16
of decimal
(c) What is the base (ii) 8
(i) 10
() 2
octal number system? (iv) 16
(d) What is the base of (ii) 8
(ii) 10
() 2
number system:
(e) (43), into binary
Convert
(ii) (110101),
(iv) (110010),
(i) (101011),
(ii) (110011),
number system:
into decimal (iv) 22
(f) Convert (10010), (ii) 20
(i) 28 (i) 18
form of ISCII?
)What is the full Interchange
Code for Information
i)International Standard
for Information Interchange
(i) Indian Standard Code
Information Interchange
International Script Code for
(ii)
(iv) None of these
of?
Hexadecimal number system is composed (iv) 16 symbols
(h) (ii) 8 symbols
(i) 10 symbols
(i) 2 symbols
number?
Which of the following is not a binary (iv) 000
0) (ii) 11E
(i) 101
(i) 1111
and letters as symbols?
numbers (iv) Hexadecimal
Which numbering system uses (ii) Octal
) Decimal (i) Binary
2.35
SOLVED QUESTIONS=
1.
What do you understand by number
system?
Ans. Number system is the technique to represent numbers in the computer system architecture. Who
data is fed into the Computer, it is converted into numeric format by ASCIl (American standard Coda
hen t
Information Interchang where each type of data is represented by its numerical equivalent. The v
of each digit in such number is determined
value
a by three things:
The digit itself
The position of the digit in the number
The base or radix of the number
Examples of number systems are: Binary, octal, decimal and hexadecimal number systems.
2. Convert
(38.625),,
into its binary equivalent.
Ans. First convert 38 into a binary number, which is:
38 Remainder
Top
19 0
9
2
1
Bottom
Hence, (38),, = (100110),
Integer Fraction
Ans. =E F. B1
= Ex 16'+ Fx 16°. Bx 16+1 x 162
= 14 x 16 +15 x 1.11 x (1/16) +1 x (1/256)
224+15.(0.6875)+ (0 .00390625)
239 +0.69140625
= 239.69140625
512+192+9
(713)0
Answer is: (713),
into hexadecimal.
6. Convert (423),,
Ans. Remainder A Top
423
16
16 26
16 1 10-A
0 1 Bottom
remainders moving from MSB to LSB. We have (1A7)..
Now, write the
Answer is: (1A7),
conversion:
7. Do the following
() (ABCD), to (?),
Ans. (1010101111001101),
(ii) (3567), to (?),
Ans. (6757,
8. Draw a truth table and logic circuit diagram of NAND gate.
Ans.
B (AB
0 1
0 1
11 o
A
B-
(AB)
9. Give the dual of (A.1)+(B.(C+0)).
Ans. (A+0).(B+(C.1))
10. The following is
message encoded in ASCII code. What is the
a
message?
1001000 1000101 1001100 1010000
Ans. Convert each 7-bit code
into its hexadecimal equivalent. The result is:
48 45 4C 50
Now locate these values in ASCIl code table and determine the character
HELP represented by each. The result is:
Data ni
numbers.
12. Explain octal and hexadecimal
choice for representing digital circuit numbers in a form that is more
is r
Ans. Octal (base 8) was previously popular
a
numbers are represented as:
is sometimes abbreviated as oct. Octal
compact than binary. Octal
14, 15, 16, 17, 20, 21 and so on.
0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13,
currently the most popular choice for representing digital numbers in circuit
Hexadecimal (base 16) is a
15. Express the following hexadecimal numbers into equivalent decimal numbers:
(i) 4A2 (i) 9E1A
(ii) 6BD (iv) 6C.34
(i) (i) (9E1A), = (40474)0
Ans. (442),, (1186),0
=
16. What is the advantage of preparing digital content in Indian language using UNICODE font?
Ans. The most important advantage of UNICODE is that we need not add/install these fonts in our system.
These are rendered automatically in the system.
17. Fill the blanks provided:
011 3
100
101 5
110 6
Sinary Octal
vanables
Sviean
8Nhatare
0 yeratie s aiss known as binary variable or logical variabile that takes its values lrom the Boolean
take dny one bnary valued quantity out of the two possible values, le,
ra Sooean vanable can
true tase. One bit repr sents one Boolean variable. In electrical circuit, it the signal passe
yes m
10
reoresents i ese tsrepresented through 0
statements?
1 What are Sooiean
Statement it it has d definite value which is either false or true
Astatement is said to be a Booesnylogica
1
Ihe values for
highlighted columns are the same. Hence, L.H.S. =
R.H.S.
23. Verify the following using truth table:
a) X.X=0
(b) X*1=1
Ans.
a) X.X=0 (b) X+1=1
X
X.X' X+1
0
Data Rans
24. (a) Convert (122), into binary number
Ans.
2 122 Rernainder
Top
2 61
2 30
15
2
2
2
0
Bottom
Therefore, (122) (11110101,
into octal number.
(b) Convert (122)
Ans.
Remainder
8122 Top
815
81
0 Bottom
(122, (172),
=
Therefore,
number.
hexadecimal
Ans.
A
B (4+8)(6C)
(CBSE D2014)
below:
for the logic circuit shown
26. Obtain the Boolean expression
Ans. F-A'.B+(C+D'
27. Write the equivalent Boolean expression for the following Logic Circuit: (CBSE D 2011)
D O-Output
None of these
(e)
Ans. (d) NOR
Boolean expression:
that can implement the following
29. ldentify the logic gates (ii) PQR+QR
(ii) X+Y.Z'
) A.B
A.B It requires AND gate.
(i)
-
Ans.
X+Y.Z'- It requires OR, AND and NOT gates.
(i) AND and NOT gates.
PQR+QR I t requires
OR,
(ii)
UNSOLVED QUESTIONS=
number.
number into binary (d) 62.325
1. Convert decimal (c) 25.80
(b) 44
(a) 52
number.
number into octal (d) 132
2. Convert decimal (c) 61
(b) 540
(a 911
hexadecimal number.
number into
3. Convert decimal (c) 206
(d) 752
(b) 3619
a) 132
number.
binary number into decimal (d) 101101
4. Convert (c) 101010.011
(b) 111101
a) 10111
decimal number.
5. Convert octal number into (c) 142
(d) 205
(b) 321
(a) 75
number.
into decimal
6. Convert hexadecimal number (d) 132
(c) 271
(b) 138
(a) A2 encoding
scheme?
different from UTF-32
scheme. How is it
Discuss UTF-8 encoding
8. What are Boolean constants?
NOT operators.
Boolean operators? Explain AND, OR,
S.Whatare
system in computers
0. What is the use of Hexadecimal number
2.
11. Verify the following using truth table:
(i) a.(a-b) =a
(ii) X.(Y Z)
=X.Y-X.z
2.Obtain the Boolean expression for the logic circuit shown belowe
20. Perform the following conversions from decimal number to other number systems:
(a) (54) (?), (b) (120), (P) =
()(76),, =
(P) d) (889), =
()
(e) (789), (?) () (108), (P)
21. Express the following binary numbers into their equivalent octal numbers:
a) 100101111 (b) 111011010 (c) 1010011 (d) 10011101
22. Express the following binary numbers into their equivalent hexadecimal numbers:
(a) 1111101101100011 (b) 100000101011100
(c) 1000111010100011 (d) 111011111
23. Express the following octal numbers into their equivalent decimal numbers.
(a) 145 (b) 6760 (c) 455 (d) 10.75
24. The hexadecimal number system uses 16 literals (0-9, A- F). Write down its base value.
25. Explore and list the steps required to type in an Indian language using UNICODE.
26. Convert the following base of number system:
(a) (1010100) (b) (3674), (.=
28. Draw the logic circuit for the following Boolean expression:
(X+Y).Z +WN
2.42
Computer Science with Python-XI
OBJECTIVE TYPE QUESTIONS=
1. Fill in the blanks.
(a) The smallest individual unit in a program is known as a . . .
(b) A word
(k) Operators that act upon two operands are referred to as operators.
aPthon supports
Unicode coding standard.
identifier must be a keyword of Python.
(b) An
variable initialization is string literal,
c) Defaut
is a valid statement.
(d) 3C=A
iel The input() always returns a value of an integer type.
T h e print() without any value or name or expression prints a blank line.
Boolean type is a sub-type of integer.
(g)In Python,
in Python.
(n)AISSCE-2020 is a valid string
0) InPython, Integer data type has a fractional part.
means "there's nothing here".
(0) Nuil literal in Python
(k) Python supports multiple assignment to multiple variables.
is used to determine the data type of variable.
) id() function a
(b) ldentifier name cannot be composed of special characters other than . **'****
SOLVED QUESTIONS=
1. What are the different components of a variable?
Ans. A variable has three main components:
(a) ldentity (memory address) of the variable.
(6) Type (data type) of the variable.
(c) Value of the variable.
2. Consider the following statements in Python interpreter and describe the output/statement required
>>> d
>>b
>>> id (d)
>>> id (b)
(B)>>> a = "Hello"
>>> a * 10
>>>a/b
>>a//b
(g) To swap the values of two variables, a and b, using multiple assignment statements.
(k)> a, b, c,d=10,27, 4+5, 10-7
>>> al/d
>>>d**d
>>>b/c
>> a+b+c-d
Ans. (a) >>> print ("Hello World")
Hello World
(b) >>> a = 10
>>>b = 12
>> c = a + b
(d) y(D)
(c) id(a)
2193248
iI
(D)
1616896960
() d b
> d
12
>>>b
12
>id (d)
1616896960
>>> id (b)
1616896960
(g)>>>a - "Hello"
>>>a*10
'HelloHelloHelloHelloHelloHelloHelloHelloHelloHello'
(h)>>> a - 10
100
>> a**3
1000
>>> a* *4
10000
(i)>>> a =15
>>>b =4
>>> a/b
3.75
>>> al/b
3
) >>>a, b = 10, 12
>>> a, b = b, a
>>> a
12
>>>b
10
i)1st_Room
i) Serial_no
(iv) Total Marks
(ii) Hundreds
(vi) total-Marks
(v) Total_Marks
(vii) True
(vi) Percentage
Ans. Following identifier names are invalid:
Reason symbo
S.No. Invalid ldentifier dentifier
cannot
contain
speia
number
(6) Serialno. cannot begin with
name
dentifier
symbol
special
(i) 1st_Room ldentifier
cannot
contain
(vii) True
variable?
and a
difference between
a keyword to the
Pytnon interpreter. Kevwor
4. What is the purpose
and meaning have been detne
they
that has a specific ror which
special word
purpose
Keyword is a only for the
Ans.
used in ourprogram
can be
r e s e r v e d words that
else, def, true,
false, etc. reserved. These are defner
elif, not fixed/
For example, for, if, Variables a r e
user-defined name given
toa value.
underscore.
Iney m u s t besin
with eithera l g
Variable is the the symbol
have letters, digits and
the user but they can
name, result_1, etc.
or underscore.
For example, _age,
")
rane:
name i n p u t ("YOur
print(name, greet_sT()) s t a t e m e n t s . So, for the
through their function call
reused anywhere
useful as they can be through functions it can
Functions are time it is needed; rather,
need not rewrite the code every
same functionality, one
be used again and again.
=
Output
return output header line
need to add colon (:) at the end of the
colon missing at the end. So, we
Ans. The function header has
Thus, the corrected code will be
decrement)
def minus (total,
=
total -
decrement
output
return output
Ans. An implicit type conversion is a conversion performed by the compiler without prograrmmer nterve
An implicit conversion is applied generally whenever multiple data types are intermived in an expres
Ans. () A variable must start with a letter or underscore followed by any number of digits and/or letter
(ii) No reserved word or standard should be used as the variable name.
(ii) No special character (other than underscore) should be included in the variable name.
Print (result)
Ans. The problem is with input() function as it returns value as a 5 it will
string, so when we input the value 13
assign to num variable as string '15' and not as integer 15. So, when num variable is multiplied the
output is '1515' and not 30. To solve this problem, int() function is to be used while accepting tne Dy
Also, Print is not a legal statement of Python; it should be print. The corrected code is:
num =
int (input ("Enter Number: "))
result = num *
print (result)
Write a program to obtain temperature in Celsius and convert it into Fahrenheit using the formula:
19.
F C*9/5+32
#Celsius to Fahrenheit
Ans.
e l s = float (input ("Enter temp in Celsius : "))
cel
emperature
p r i n t ("Ten in Celsius is : ", cels)
*
9/5 + 32
f =cels
print ("Temperature in Fahrenheit is : ", £)
20, What will be the output produced by the following code?
name = "Neeru
age= 21
print (name, "you are", 21, "now but", )
print ("you will be", age + 1, "next year")
Y, x + 2
print (x, y)
Ans. 6 4
Explanation: The first line of code assigns values 2 and 6 to variables x and y respectively.
The next line (second line) of code first evaluates the right-hand side, ie., y, x + 2, which is 6, 2+2, ie., 6,4;
And then assigns this to x, y, i.e., x, y = 6, 4; so x gets 6 and y gets 4.
accepted by user.
Ans. c o s t P r i c e = i n t (input ( ' E n t e r c o s t p r i c e : '))
profit = i n t (input ( ' E n t e r p r o f i t : '))
sellingPrice = costPrice + profit
Output:
Enter cost price: 50
Enter profit : 12
Selling Price: 62
23. What output will be produced by the following code:
A, B, C, D = 9.2, 2.0, 4, 21
print (A/4)
print (A//4)
print (B**C)
print (A%C)
Ans. 2.3
2.0
16.0
1.1999999999999993
4 Write the Python code to convert the time given in minutes into hours and minutes.
else Year")
"is Not a Leap Calculate and
print (year, pencil from the
user.
and quantity of
program
that accepts cost price
28. Write a Python
int (input (
totalprice=costprice* qty
is: ", totalprice)
print ("Total price and angle store the length
of the
wall. Let variables length
29. Assume that a ladder is put
upright against a program to
as it leans against
the wall. Write a Python
forms with the ground
ladder and the angle that it values of length and angle:
reached by the ladder on the wall for the following
compute the height
(b) 20feet and 0 degree
a) 16 feet and 75 degrees
(c) 24 feet and 45 degrees (d) 24feet and 80 degrees
Forexample,
=5
len( ' h e l l o ' )
"<stdin>": line 1
File
ntaxError : can't ass1gn to function call
Run-time Error: These errors are generated during a program executi due to resource limitation such as
ivision by zero, trying to access an identifier or file which doesn't exists, etc. Python has provision of
hk
cheo Doints to handle these errors known as Exception Handling.
For example,
a=10
b=0
ca/b
Would result in
7eroDivisionError: division by zero
29 Fxolain the concept of R-value and L-value with example.
Anc. In a normal expression, the variable to the left side of an assignment operator refers to L-value (left-value)
refers to
because it resides in memory and is addressable, and an expression after the assignment operator
R-value (right-value). It does not represent an object occupying some identifiable location in memory.
For example, X=1 #X is an L-value
Y=20 #Y is an L-value
Z=X+Y #X+Y is an R-value
33. Write the output of the following:
(a) numl =
4
num2= numl +1
num1 = 2 print (numl, num2)
num2 =
2, 6
(b) numl,
numl, num2 =
num2, numl + 2
Ans. (a) 2, 5
(b) 6, 4
'num3' is not defined
c) NameError: name
are")
print ("Be fore Swapping Values
print ("Val ue of First Variable
a is", a)
b is", b)
print ("Value of Second Variable
C a
a b
b C
print ("After Swapping Values are")
Variable a is", a)
Print ("Value of First
Variable b is", b)
print ("Value of Second
35. Write third
a program to swap two numbers without using a
variabie
Ans.
int (input ("Enter First Number ")
D int (input (" Enter Second Number"))
OR
int (input ("Enter First Number"))
b = int (input ("Enter Second Nurmber"))
print ("Before Swapping Values are")
print ("Value of First Variable a is", a)
print ("X=", X)
print ("Y=", Y)
print ("Z=", Z)
Ans. (i) False
(ii) X=10.0
Y7.0
Z=4.0
UNSOLVED QUESTIONS=
command to display your school name, class and section, separated by ""
2. Write Python
3. Evaluate the following expressions manually:
(i) (2+3) **3-6/2 (i) (2+3)
*
5//4 + (4 + 6)/ 2
(ii) 1 2 + (3 * 4 - 6 ) / 3 (iv) 12 +(3**4-6// 2
(v) 12 * 3 %5+2 * 6//4 (vi) 12 % 5 *3+(2*6)//4 nually
calculator and verify the results that you get man
4. Evaluate the above expressions by using IDLE as a
x+=y x+=Y
print (x, y) Y-=X
print (x, y)
(3) a=5 (4) p=10
b-2*a q-20
at=a+b
p*=q/3
b*=a+b gt=p+q*2
print (a, b) print (P,q)
p=582 (6) p-21//5
(5)
p**4 p4
r=p//q r=p*q
pt=ptqtr pt ptq-r
rt=p+q+r r*=p-qtr
g-=p+q*r qt=ptg
print (P, q, r) print (p, q, r)
Write Python expressions equivalent to the following arithmetic/algebraic expressions:
(2)+9 (3) 3+
2
15. Modify the above function to take a third parameter called shape type. Shape type should be either triangle
or rectangle. Based on the shape, it should calculate the area. Formula used:
Area of a Rectangle length*width.
16.
Write function called print_pattern
a
pattern if the input number is 3:
that takes integer number as argument and prints the following
***
***
****
print (a And b)
(3) a, b, C =2, 8, 9
print (a, b, c)
C, b, a t a, b, C
print (a ; b; c)
(4)x = 24
4 x
(5) Print ("X =" X)
21. What will be the output produced by the following code fragment(s)?
(1) X = 10
X X + 10
X = X - 5
print (X)
X, Y =X 2, 22
print (X, Y)
(2) first = 2
second = 3
third = first * second
#side given as 7
area = side * side
print (a)
b 4
print (b)
S atbb
print (s)
(2) Name = "Prateek"
Age = 26
24.
x 40
x20, Ytx
print (x, y)
output.
the
Give
5,
=
20, 60
y
X *, Y
*
10, x + 10
X, Y
y,
print(x, y)
the output.
Give
26. 13
b
=
12,
a,
a/2
C,
b a *2,
(a, b, c)
print
output.
Give the
27.
b, c
=
10, 20, 30
a,
a +3, b -4
9 r =C~5,
P,
P , g, r)
print('a and b,
the following code fragment. (The input entered as XI)
98 Find errors in
("Enter your class:"))
c
int (input
Ans. C / U s e r s / p r e e t i / A p p D a t a / L o c a l / P r o g r a m s / P y t h o n / P y t h o n 3 7 - 3 2 / p r
avgcost_share-total_amt/total_shares
2. EX500 is an India based Cargo company that deals in the export and
selling of various pond.
country as well as abroad. To do business analysis of day-to-day transactions,
they have hireddaa programrt
nh
to develop a computerized system for the purp0se.
Write a Python code that accepts cost of goods sold
(cogs), revenue generated (re), operating.coete t
prints gross profit (gp), net profit (np) and net profit percentage (npp). [Net profit
Revenu =
yenue og-
Ans.
rogevenselpy-CAewpreeti/AppDtalocayProgramy/yhanvty
Pldia lema hun Options Vlndow Hely
0
PEOgram to calculate Gross profit, net profit and
e t profit percentage
cog nt (input f g90ds 3o1d ))
gint(input ( 9nerated "))
Oc int (input (
9P Ig cogsGroBsprofit
np g P OC Net protit
npp np/rg*100 Net profit percentage
print(
print( np)
print( npp)
n 14 Cto
Pyhon 370 Shel
Fe Ld hDebu Optens Vinden p
hore intormation.
RESTART: C:/Users/preeti/AppData/local/progra
ms/Python/Python 37-32/pr09 revenue1.pY
Lnter cost of goods sold: 100000
Enter revenue generated : 150000
Enter operating cost 12000
Gross profit is 50000
Het profit is 3800
Net profit percentage is 25.333333333333336
In11 Cel4
3. Gurukul Vidyapeeth is a reputed institution in the field of academics and extracuricular activities and involved
in the overall growth of every child. Every year, with the commencement of the new sesion, it hikes fee by 10%
for all the students which was done manually till now and required enormous efforts on the part of office staft.
To solve this problem, develop a Python program that automatically calculates this 10% fee hike every year
after obtaining the basic fee amount from the user and displays it for the parents of students enrolled witn
the institute.
Ans.
Laprog seeike.oy Chers/prenti/AppData/Loc-
File f4t fnmat Run Opions Windon Hdp
9Program to calculate 108 fee hike
&mount int(input("Enter Arnount '))
1ee_hike 0.1"amount
total_fee amount fee_hike
print"Fee Iy paY ',total_fee)
Pyrthon 3:70 Shel
Fle lda heli Dehup oplions Window Halp
RESTART C:/Users/preeti/hppData/Loca
1/Prograns/Python/Python37-32/prog_fee
hike.py
Enter Amount 120000
Fee to pay now: 132000.0
YI