CS Holiday HW
CS Holiday HW
ANNUR-641 653
HOMEWORK-1
(TOPICS: Python Revision Tour 1 and 2)
Subject: Computer Science (083) Class: XII Date:15.05.23
Answer the following:
1. Which of the following is an invalid variable?
(a) my_day_2 (b) 2nd_day (c)Day_two (d) _2
2. Which of the following is not a keyword?
(a) eval (b) assert (c) nonlocal (d) pass
3. Which of the following cannot be a variable?
(a) __init__ (b) in (c) it (d) on
4. Which of these is not a core data type?
(a) Lists (b) Dictionary (c) Tuples (d) Class
y
5. How would you write x in Python as an expression?
(a) x^y (b) x**y (c) x^^y (d) none of these
6. What will be the value of the expression? 14 +13 % 15
(a) 14 (b) 27 (c) 12 (d) 0
7. Evaluate the expression given below if A = 16 and B = 15. A%B//A
(a) 0.0 (b) 0 (c) 1.0 (d) 1
8. What is the value of x? x = int(13.254/2)
(a) 7 (b) 4 (c) 6 (d) 13
9. The expression 8/4/2 will evaluate equivalent to which of the following expressions:
(a) 8/(4/2) (b) (8/4)/2
10. Which among the following list of operators has the highest precedence?
+ ,-,**,%, /,<< ,>> , |
(a) <<, >> (b) ** (c) | (d) %
11. Which of the following expressions results in an error?
(a) float('12') (b) int('12') (c) float('12.5') (d) int('12.5')
12. Which value type does input() return?
(a) Boolean (b) String (c) Int (d) Float
13. Which two operators can be used on numeric values in Python?
(a) @ (b) % (c) + (d) #
14. Which of the following is valid arithmetic operator in Python:
(a) // (b) ? (c) < (d) and
15. The numbered position of a letter in a string is called _____.
(a) position (b) integer position (c) index (d) location
16. The operator _____ tells if an element is present in a sequence or not.
(a) exists (b) in (c) into (d) inside
17. The keys of a dictionary must be of _____ types.
(a) Integer (b) mutable (c) immutable (d) any of these
18. Following set of commands is executed in shell, what will be the output?
>>>str = "hello"
>>>str[ : 2]
>>>
(a) he (b) lo (c) olleh (d) hello
19. What data type is the object below?
L = [1, 23, 'hello', 1]
(a) list (b) dictionary (c) array (d) tuple
20. What data type is the object below?
L = 1, 23, 'hello', 1
(a) list (b) dictionary (c) array (d) tuple
21. To store values in terms of key and value, what core data type does Python provide?
(a) list (b) tuple (c) class (d) dictionary
22. What is the value of the following expression? 3 + 3.00, 3**3.0
(a) (6.0, 27.0) (b) (6.0, 9.00) (c) (6, 27) (d) [6.0, 27.0] (e) [6, 27]
23. List AL is defined as follows: AL = [1, 2, 3, 4, 5] Which of the following
statements removes the middle element 3 from it so that the list AL equal [1, 2, 4, 5]?
(a) del AL[2] (b) AL[2 : 3] = [] (c) AL[2:2] = [] (d) AL[2] = [] (e) AL.remove(3)
24. Which two lines of code are valid strings in Python?
(a) This is a string (b) 'This is a string' (c) (This is a string) (d) "This is a
string"
25. You have the following code segment:
String1 = "my"
String2 = "work"
print(String1 + String2)
What is the output of this code?
(a) my work (b) work (c) mywork
d1 = dict[]
i=1
n = input ("Enter number of entries : ")
while i <= n :
a = input ("Enter name:")
b = input ("Enter age:")
d1 (a) = b
i=i+1
L= d1.key []
for i in L :
print (i, '\t', 'd1[ i ]')
5. What is None literal in Python? (1)
6. Can non graphic characters be used and processed in Python? How? Give examples to
support your answer. (2) (OR)
7. What is an expression and a statement? (2)
8. What is the output produced by the following code snippets: (5)
i) x=45
while x<50:
print(x)
ii) x=”apple,pear,peach”
y=x.split(“,”)
for z in y:
print(z)
iii) x=’apple,pear,peach,grapefruit’
y=x.split(“,”)
for z in y:
if z<‘m’:
print(str.lower(z))
else:
print(str.upper(z))
9. What’s a[1:1] if a is a string of at least two characters? And What if string is shorter?
(1)
10. What are the two ways to remove something from a list? How are they different? (2)
(OR)
11. How is del D and del D[<key>] different from one another if D is a dictionary?(2)
SRI AMBAL THULASI PUBLIC SENIOR SECONDARY SCHOOL-CBSE,
ANNUR-641 653
HOMEWORK-4
(TOPIC: Working with functions)
Subject: Computer Science (083) Class: XII Date:18.05.23
2. In which of the following file modes the existing data of the file will not be lost?
i) rb ii) w iii) a+b iv) wb+ v) r+ vi) ab vii) w+b viii)wb ix) w+
4. Suppose a file name test1.txt store alphabets in it then what is the output of the
following code:
f1=open("test1.txt")
size=len(f1.read())
print(f1.read(5))
5. Write a user defined function in python that displays the number of lines starting with
'H'in the file para.txt.
6. Write a function countmy() in python to read the text file "DATA.TXT" and count the
number of times "my" occurs in the file.
The countmy() function should display the output as:"my occurs 2 times".
7. Write a program that copies a text file "source.txt" onto "target.txt" barring the lines
starting with @ sign.
1. Write PushOn(Book) and Pop(Book) methods/functions in Python to add a new Book and
delete a Book from a list of Book titles, considering them to act as push and pop operations
of the Stack data structure.
4. Write a program to Count the number of characters from a file. (Don’t count white
spaces).
5. Write a program to Count number of lines in a text file.
2. Write code to print just the last line of a text file “data.txt”.
3. Write a function DisplayHeShe() in python that counts the number of „He‟ or She‟
words present in a text file „Text.txt‟
6. Write a python program to append a new records in a binary file –“student.dat”. The
record can have Rollno, Name and Marks.
7. Write a python program to search and display the record of the student from a binary
file “Student.dat” containing students records (Rollno, Name and Marks). Roll number of
the student to be searched will be entered by the user.
1.
2.
3.
1. Name the Python Library modules which need to be imported to invoke the following
functions : (i) load () (ii) pow () (iii) Uniform () (iv) fabs () (v) sqrt() (vi)dump() (vii)ceil()
(viii)randrange()
8. Explain with a code about Positional arguments, Keyword arguments and Default
arguments.
10. What possible outputs(s) are expected to be displayed on screen at the time of
execution of the program from the following code? Also specify the minimum and maximum
values that can be assigned to the variable End.
import random
Colours = ["VIOLET","INDIGO","BLUE","GREEN", "YELLOW","ORANGE","RED"]
End = randrange(2)+3
Begin = randrange(End)+1
for i in range(Begin,End):
print(Colours[i],end="&")
(i) INDIGO&BLUE&GREEN& (ii) VIOLET&INDIGO&BLUE& (ii)
BLUE&GREEN&YELLOW& (iv) GREEN&YELLOW&ORANGE&
12. A non-key attribute, whose values are derived from primary key of some other table.
i. Alternate Key ii. Foreign Key iii. Primary Key iv. Candidate Key
13. Differentiate between DDL and DML with one Example each.
14. Differentiate between fetchone() and fetchmany() methods with suitable examples for
each.
15. What is the difference between CHAR & VARCHAR data types in SQL? Give an
example for each.
16. Differentiate between an Attribute and a Tuple in a Relational Database with suitable
example.