0% found this document useful (0 votes)
13 views14 pages

Xi-Cs Worksheet & Ak

This document is a revision worksheet for Grade XI Computer Science students at Delhi Public School Bangalore East, covering various topics including fill-in-the-blanks, matching exceptions, assertions, multiple-choice questions, and coding exercises. It includes questions on Python programming, logic gates, and data types, along with an answer key for self-assessment. The worksheet aims to prepare students for their midterm exams by testing their understanding of computer science concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views14 pages

Xi-Cs Worksheet & Ak

This document is a revision worksheet for Grade XI Computer Science students at Delhi Public School Bangalore East, covering various topics including fill-in-the-blanks, matching exceptions, assertions, multiple-choice questions, and coding exercises. It includes questions on Python programming, logic gates, and data types, along with an answer key for self-assessment. The worksheet aims to prepare students for their midterm exams by testing their understanding of computer science concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

DELHI PUBLIC SCHOOL BANGALORE EAST

REVISION WORKSHEET- MIDTERM EXAM


GRADE XI
SUBJECT: COMPUTER SCIENCE (083)

NAME:______________ SEC:_________ ROLL NO:_______

I. Fill in the blanks:


1. (i) X + X’ = ____ (ii) X’’= ________
2. Which gate returns true if both inputs are similar otherwise false
II. Match the following to identify the correct Exception:
i) >>>100/0 a)OverflowError

ii) Result of the arithmetic operation b)ValueError


is too large to be represent.
iii) Identifier name is not found c)ZeroDivisionError
iv) >>>int(“89.5”) d)NameError
III. ASSERTION & REASON:
a) Both A and R are correct and R is the correct explanation of A
b) Both A and R are correct but R is NOT the correct explanation of A
c) A is correct but R is not correct
d) A is not correct but R is correct.
1. A: An identifier cannot have the same name as of a keyword.
R: Python interpreter will not be able to differentiate between a keyword and an identifier having
the same name as of a keyword.
2. A:In Python comments are interpreted and are shown on the output screen.
R:Single line comments in python starts with # character
3. A: The below code will give error message when executed.
num1=input("enter a number")
print(num1+2)
R: input() returns a string datatype. We cannot add string data type with a numeric datatype. So,
performing arithmetic operation on it will result in error.
IV. OBJECTIVE TYPE QUESTIONS (MCQ)
1. >>> print("I" + "am" + "in" + "school") display
(a) I am in school (b)I Am In School (c)Iaminschool (d)iaminschool
2. Which of the following is an invalid identifier to be used in Python?
(a) per%marks (b) _for (c) While (d) true
3.Which of the following is not a valid declaration?
(a) S=12 (b) V="J" (c) F=32.4 (d) H=0254
4.All keywords in python except True,False and None are in?
(a) Lower case (b) Upper case (c) Capitalized (d) None of the above
5.Which of the following expressions is an example of type casting?
(a) 4.0+float(6) (b) 5.3+6.3 (c) 5.0+3 (d) None of these

1|Page
6. In Python, a variable may be assigned a value of one type, and then later assigned a value of a
different type.
(a) True (b) False (c) Only for numeric types (d) Only if type casting is done
7.Which of the following is an invalid statement?
(a) xyz=1,000,000 (b) x y z = 100 200 300
(c) x,y,z=100,200,300 (d) x=y=z=1,000,000
8.Predict the output of the following code:
import statistics as S
D=[4,4,1,2,4]
print(S.mean(D),S.mode(D))
(a) 1 4 (b) 4 1 (c) 3 4 (d) 4 3
9. Which of the following is an incorrect logical operator in python?
(a) not (b) in (c) or (d) and
10.Which of the following symbols are used for comments in Python?
(a) // (b) & (c) /**/ (d) #
11.Choose the correct data type for given example.
a=[5,4,9,’a’,’b’]
(a) List (b) Tuple (c) string (d) None of above
12.What will be value of diff?
c1='A'
c2='a'
diff=ord(c1)-ord(c2)
print(diff)
a) Error: unsupported operator ‘-‘ b) 32 c) -32 d) 0
13. In Python, math.pow(a,b) is equivalent to a**b. Is this statement correct?
a) Yes, always equivalent
b) No, math.pow() always returns float whereas ** may return int
c) No, math.pow() works only on integers
d) None of these
V. Answer the following:
1.int(‘a’) produces error but the following expression having int(‘a’) in it, does not return error. Why?
>>>len(‘a’)+2 or int(‘a’)
2. The input to the following digital circuit

i) Write expression for the output Y.


ii) Which logic gates are used in the given digital circuit?
iii) Write the truth table of Y.
3.Write the dual and complement of the following expressions:

2|Page
i) A+AB=A
ii)A+1=1
iii)(AB)′+C
4. Write an algorithm to find the largest of 3 given numbers
5.Write a Python code to create a dictionary named ‘house’ with keys as house names (Cauvery,
Ganga, Narmada, Godavari) and values as house colors (Red, Green, Yellow, Blue)
6.Write the logical expressions in Python for the following conditions (assume variables a, b, c, str1,
str2, str3, num already store valid values):
i) Verify that the result of multiplying 5 with –4 is different from 15.
ii) Check whether x is not in the range 100 to 200 (inclusive).
iii) Confirm that the average of b and c is strictly between 25 and 100.
iv) Test whether num is a multiple of both 3 and 5, but not a multiple of 10.
7. Answer the following question:
x, y = 15, 25
if x > 10:
if y < 20:
pass # STATEMENT 1
else:
if x + y > 40:
print("RESULT A") # STATEMENT 2
else:
print("RESULT B") # STATEMENT 3
else:
if x == y:
print("RESULT C") # STATEMENT 4
else:
pass # STATEMENT 5
Questions:
i) What is the purpose of STATEMENT 1 and STATEMENT 5 in the above code?
ii) Will STATEMENT 1 or STATEMENT 5 execute in this program? Justify your answer.
iii) What will be the final output of the program?
VI. Write the output of the code given below:
1 p = 10
q = 20
p *= q // 3
p = q ** 2
print(p, end='.')
q += p
print(q)
2 V, W, X = 20, 15, 10
W, V, V = X-2, V+3, W*2
print(V, X, W, sep='*')
3 Evaluate the following expressions:
a)5 // 10 * 9 % 3 ** 8 + 8 – 4
b)65 > 55 or not 8 < 5 and 0 != 55
c)10 +(5-2) * 4 + 2**3**2
4 x = True
y = False
z = False

3|Page
if not x or y :
print( 1)
elif not x or not y and z:
print( 2)
elif not x or y or not y and x:
print( 3)
else:
print( 4)
5 What will be the result of following expression:
a. len(“Papaya”)
b. “divya”>”Divya
6 Evaluate the following.
i) >>>-5//-3
ii) >>>18%-4
iii) 'HELLO' and ''
iv) 'HELLO' or ''
7 What possible output(s) are expected to be
displayed at the time of execution of the
following code? Also specify the maximum
values that can be assigned to each of the
variables FROM and TO.
import random
FROM = random.randint(5, 15)
TO = random.randint(25, 45)
print(FROM, TO, sep="#")
Options:
(i) 25#25 (ii) 15#35 (iii) 12#40 (iv) 18#45
8 x=0
a=5
b=5
if a > 0:
if b < 0:
x=x+5
elif a > 5:
x=x+4
else:
x=x+3
else:
x=x+2
print(x)
9 >>>math.floor(-45.17)
>>>math. sqrt (64)
>>>math.fabs(-15.3)
>>>math.ceil(-10.01)
10 n1=int(input("Enter an Integer"))
n2=int(input("Enter an Integer"))
if n1<=0:

4|Page
n2=n2+1
else:
n1=n1+1
if n1>0 and n2>0:
print("W",end='@')
elif n1>0:
print("X",end='@')
if n2>0:
print("Y",end='@')
else:
print("Z")
i)If the user enters 12 for n1 and 23 for n2
ii)If the user enters -12 for n1 and -23 for n2
iii)If the user enters -100 for n1 and 0 for n2
VII. Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code
1 a, b = 0
if (a = b)
a +b = c
print z
2 Rewrite the following code fragment remove and
operator and use chaining of comparison operators.
Logic of program should not change.
if(score <33 ):
grade=“F”
if(score >=33 and score < 45 ):
grade=“E”
if(score >=45 and score < 60 ):
grade=“D”
if(score >=60 and score <75 ):
grade=“C”
if(score >=75 and score <90 ):
grade=“B”
if(score >= 90 ):
grade=“A”
print (grade)
VIII. Write the program for the following:
1.Write a program to enter two integers and perform all arithmetic operations on them.
2.Write a program to check a character is vowel or not.
3.Write a program for checking whether the given character is uppercase ,lowercase,digit ,special
symbol or white space.
4. An organization wants to give its employees a bonus based on the following conditions:
• If the employee is male: The bonus will be 10% of the salary if the salary is less than 50,000;
otherwise, the bonus will be 15%.
• If the employee is female:The bonus will be 20% of the salary if the salary is less than 50,000;
otherwise, the bonus will be 25%.
Write a program to calculate the bonus using the above conditions

5|Page
DELHI PUBLIC SCHOOL BANGALORE EAST
REVISION WORKSHEET- MIDTERM EXAM (ANSWER KEY)
GRADE XI
SUBJECT: COMPUTER SCIENCE (083)

NAME:______________ SEC:_________ ROLL NO:_______

I. Fill in the blanks:


1. (i) X + X’ = ____ (ii) X’’= ________
2. Which gate returns true if both inputs are similar otherwise false

Ans:
1. (i) X + X’ = 1 (ii) X’’ = X
2. XNOR gate

II. Match the following to identify the correct Exception:


i) >>>100/0 a)OverflowError

ii) Result of the arithmetic operation b)ValueError


is too large to be represent.

iii) Identifier name is not found c)ZeroDivisionError


iv) >>>int(“89.5”) d)NameError

Ans:
i-c ,ii-a, iii-d, iv-b

III. ASSERTION & REASON:

a) Both A and R are correct and R is the correct explanation of A


b) Both A and R are correct but R is NOT the correct explanation of A
c) A is correct but R is not correct
d) A is not correct but R is correct.
1. A: An identifier cannot have the same name as of a keyword.
R: Python interpreter will not be able to differentiate between a keyword and an identifier
having the same name as of a keyword.
2. A:In Python comments are interpreted and are shown on the output screen.
R:Single line comments in python starts with # character
3. A: The below code will give error message when executed.
num1=input("enter a number")
print(num1+2)
R: input() returns a string datatype. We cannot add string data type with a numeric datatype. So,
performing arithmetic operation on it will result in error.

1|Page
1. A
2. D
3. A

IV. OBJECTIVE TYPE QUESTIONS (MCQ)


1. >>> print("I" + "am" + "in" + "school") display
(a) I am in school (b)I Am In School (c)Iaminschool (d)iaminschool
2. Which of the following is an invalid identifier to be used in Python?
(a) per%marks (b) _for (c) While (d) true
3.Which of the following is not a valid declaration?
(a) S=12 (b) V="J" (c) F=32.4 (d) H=0254
4.All keywords in python except True, False and None are in?
(a) Lower case (b) Upper case (c) Capitalized (d) None of the above
5.Which of the following expressions is an example of type casting?
(a) 4.0+float(6) (b) 5.3+6.3 (c) 5.0+3 (d) None of these
6. In Python, a variable may be assigned a value of one type, and then later assigned a value of a
different type.
(a) True (b) False (c) Only for numeric types (d) Only if type casting is done
7.Which of the following is an invalid statement?
(a) xyz=1,000,000 (b) x y z = 100 200 300
(c) x,y,z=100,200,300 (d) x=y=z=1,000,000
8.Predict the output of the following code:
import statistics as S
D=[4,4,1,2,4]
print(S.mean(D),S.mode(D))
(a) 1 4 (b) 4 1 (c) 3 4 (d) 4 3
9. Which of the following is an incorrect logical operator in python?
(a) not (b) in (c) or (d) and
10.Which of the following symbols are used for comments in Python?
(a) // (b) & (c) /**/ (d) #
11.Choose the correct data type for given example.
a=[5,4,9,’a’,’b’]
(a) List (b) Tuple (c) string (d) None of above
12.What will be value of diff?
c1='A'
c2='a'
diff=ord(c1)-ord(c2)
print(diff)
a) Error: unsupported operator ‘-‘ b) 32 c) -32 d) 0
13. In Python, math.pow(a,b) is equivalent to a**b. Is this statement correct?
a) Yes, always equivalent
b) No, math.pow() always returns float whereas ** may return int
c) No, math.pow() works only on integers
d) None of these

Ans:
2|Page
1(c), 2(a), 3(d), 4(a), 5(a), 6(a), 7(b), 8(c), 9(b), 10(d), 11(a), 12(c), 13(b)
V. Answer the following:
1..int(‘a’) produces error but the following expression having int(‘a’) in it, does not return error.
Why?
>>>len(‘a’)+2 or int(‘a’)
ANS:
The or operator in Python evaluates the left operand first. If the left operand is
True, the or operator returns the left operand and does not evaluate the right
operand
2 The input to the following digital circuit

i) Write expression for the output Y.


ii) Which logic gates are used in the given digital circuit?
iii) Write the truth table of Y.
ANS:
i) Y=(AB)′+C′
ii) Gates used
-2 input NAND
-1 NOT
-2 input OR

iii)

A B C AB (AB)' C' Y = (AB)' + C'


0 0 0 0 1 1 1
0 0 1 0 1 0 1
0 1 0 0 1 1 1
0 1 1 0 1 0 1
1 0 0 0 1 1 1
1 0 1 0 1 0 1
1 1 0 1 0 1 1
1 1 1 1 0 0 0
3.Write the dual and complement of the following expressions:
i) A+AB=A
ii) A+1=1
iii)(AB)′+C
Ans:
i) Dual: A⋅(A+B)=A
Complement: (A+AB)′=A′

3|Page
A′.(AB) ′=A′
A′.(A′+B′)=A′
ii) Dual: A⋅0=0
Complement: (A+1)′=0
A′.0=0
iii)Dual: (A+B)′⋅C
Complement: ((AB)′+C)′
=AB.C′
4. Write an algorithm to find the largest of 3 given numbers

ANS: Algorithm
Step 1: Start
Step 2: Input a,b,c
Step 3: if a>b then go to step 4 otherwise goto step 6
Step 4: if a>c then go to step 5 otherwise goto step 8
Step 5:display a goto step 9
Step 6:if b>c then goto step 7 otherwise go to step 8
Step 7: display b goto step 9
Step 8:Display c
Step 9: Stop/End
5.Write a Python code to create a dictionary named ‘house’ with keys as house names (Cauvery,
Ganga, Narmada, Godavari) and values as house colors (Red, Green, Yellow, Blue)
ANS:
house = { 'Cauvery': 'Red', 'Ganga': 'Green', 'Narmada': 'Yellow',
'Godavari': 'Blue'}

6.Write the logical expressions in Python for the following conditions (assume variables a, b, c,
str1, str2, str3, num already store valid values):
i) Verify that the result of multiplying 5 with –4 is different from 15.
ii) Check whether x is not in the range 100 to 200 (inclusive).
iii) Confirm that the average of b and c is strictly between 25 and 100.
iv) Test whether num is a multiple of both 3 and 5, but not a multiple of 10.
Ans:
i) (5 * -4) != 15
ii) not (100 <= x <= 200)
iii) ((b + c) / 2 > 25) and ((b + c) / 2 < 100)
iv) (num % 3 == 0) and (num % 5 == 0) and (num % 10 != 0)
7. Answer the following question:
x, y = 15, 25
if x > 10:
if y < 20:
pass # STATEMENT 1
else:
if x + y > 40:
print("RESULT A") # STATEMENT 2
else:

4|Page
print("RESULT B") # STATEMENT 3
else:
if x == y:
print("RESULT C") # STATEMENT 4
else:
pass # STATEMENT 5

Questions:
i) What is the purpose of STATEMENT 1 and STATEMENT 5 in the above code?
ii) Will STATEMENT 1 or STATEMENT 5 execute in this program? Justify your answer.
iii) What will be the final output of the program?

ANS:

i)STATEMENT 1 (pass): Placeholder inside the branch if y < 20:. It avoids syntax
errors since an if cannot have an empty body.

• STATEMENT 5 (pass): Same purpose — placeholder in the else block of


the outer if. It ensures valid syntax when no code is needed.

ii)STATEMENT 1: Will not execute because the condition y < 20 is False (25 <
20 is False).

STATEMENT 5: Will not execute because the outer if x > 10 is True, so the else
part (where STATEMENT 5 is) is skipped.

So neither STATEMENT 1 nor STATEMENT 5 executes.


iii) RESULT B

VI. Write the output of the code given below:

1 p = 10 400.420
q = 20
p *= q // 3
p = q ** 2
print(p, end='.')
q += p
print(q)
2 V, W, X = 20, 15, 10 30*10*8
W, V, V = X-2, V+3, W*2
print(V, X, W, sep='*')
3 Evaluate the following expressions: a)4
a)5 // 10 * 9 % 3 ** 8 + 8 – 4 b)True
b)65 > 55 or not 8 < 5 and 0 != 55 c)534
c)10 +(5-2) * 4 + 2**3**2
4 x = True 3
y = False

5|Page
z = False
if not x or y :
print 1
elif not x or not y and z:
print 2
elif not x or y or not y and x:
print 3
else:
print 4
5 What will be the result of following a)6
expression: b)True
a. len(“Papaya”)
b. “divya”>”Divya

6 Evaluate the following. ANS:


i) 1
i) >>>-5//-3 ii) -2
ii) >>>18%-4 iii) ‘’ EMPTY STRING
iii) 'HELLO' and '' iv) HELLO
iv) 'HELLO' or ''
7 What possible output(s) are expected to be (ii) 15#35 (iii) 12#40
displayed at the time of execution of the
following code? Also specify the maximum
values that can be assigned to each of the
variables FROM and TO.
import random
FROM = random.randint(5, 15)
TO = random.randint(25, 45)
print(FROM, TO, sep="#")
Options:
(i) 25#25 (ii) 15#35 (iii) 12#40 (iv) 18#45
8 x=0 3
a=5
b=5

if a > 0:
if b < 0:
x=x+5
elif a > 5:
x=x+4
else:
x=x+3
else:
x=x+2

print(x)
9 >>>math.floor(-45.17) -46 ( returns int)

6|Page
>>>math. sqrt (64) 8.0 ( returns float)
>>>math.fabs(-15.3) 15.3
>>>math.ceil(-10.01) -10 ( returns int)
10 n1=int(input("Enter an Integer")) ANS:
n2=int(input("Enter an Integer")) a)
if n1<=0: i) W@Y@
n2=n2+1 ii)Z
else: iii) Y@
n1=n1+1
if n1>0 and n2>0:
print("W",end='@')
elif n1>0:
print("X",end='@')
if n2>0:
print("Y",end='@')
else:
print("Z")
i)If the user enters 12 for n1 and 23 for n2
ii)If the user enters -12 for n1 and -23 for n2
iii)If the user enters -100 for n1 and 0 for n2

VII. Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code
1 a, b = 0 a=b = 0
if (a = b) if (a = =b):
a +b = c c=a+b
print z print(c)
2 Rewrite the following code fragment remove and if score < 33:
operator and use chaining of comparison operators. grade = "F"
Logic of program should not change. elif 33 <= score < 45:
if(score <33 ): grade = "E"
grade=“F” elif 45 <= score < 60:
if(score >=33 and score < 45 ): grade = "D"
grade=“E” elif 60 <= score < 75:
if(score >=45 and score < 60 ): grade = "C"
grade=“D” elif 75 <= score < 90:
if(score >=60 and score <75 ): grade = "B"
grade=“C” elif score >= 90:
if(score >=75 and score <90 ): grade = "A"
grade=“B”
if(score >= 90 ): print(grade)
grade=“A”
print (grade)

VIII. Write the program for the following:


1.Write a program to enter two integers and perform all arithmetic operations on them.
Ans:
num1 = int(input("Enter first number: ")) #Input Second number

7|Page
num2 = int(input("Enter second number: "))
print("Addition: ",num1+num2)
print("Subtraction: ",num1-num2)
print("Multiplication: ",num1*num2)
print("Division: ",num1/num2)
print("Modulus: ", num1%num2)
print("Floor Division: ",num1//num2)
print("Exponentiation: ",num1** num2)

2.Write a program to check a character is vowel or not.


ANS:
ch = input("Enter a character: ")
if ch in 'aeiouAEIOU':
print(ch, "is a vowel.")
else:
print(ch, "is not a vowel.")
3.Write a program for checking whether the given character is uppercase ,lowercase,digit ,special
symbol or white space.

Ans:
ch = input("Enter a character: ")
if len(ch) != 1:
print("Please enter only one character")
else:
if 'A' <= ch <= 'Z':
print("Uppercase letter")
elif 'a' <= ch <= 'z':
print("Lowercase letter")
elif '0' <= ch <= '9':
print("Digit")
elif ch == ' ':
print("Whitespace")
else:
print("Special symbol")
4. An organization wants to give its employees a bonus based on the following conditions:
• If the employee is male:
o The bonus will be 10% of the salary if the salary is less than 50,000; otherwise,
the bonus will be 15%.
• If the employee is female:
o The bonus will be 20% of the salary if the salary is less than 50,000; otherwise,
the bonus will be 25%.
Write a program to calculate the bonus using the above conditions
ANS:
gender = input("Enter gender (male/female): ").lower()
salary = float(input("Enter salary: "))
if gender == "male":

8|Page
if salary < 50000:
bonus = 0.10 * salary
else:
bonus = 0.15 * salary
elif gender == "female":
if salary < 50000:
bonus = 0.20 * salary
else:
bonus = 0.25 * salary
else:
bonus = 0
print("Invalid gender entered!")
print("Bonus:", bonus)
print("Total salary with bonus:", salary + bonus)

***********************

9|Page

You might also like