Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

AUTUMN BREAK ASSIGNMENT I

XII COMPUTER SCIENCE

1. What is a literal in Python? How many types of literals are allowed in Python?
2. What is None in Python?
3. What are Python’s built-in core data types?
4. Out of the following, find the invalid identifiers –
Price*Qty, class, For, do, 3rdcol, totally, Row31, _Amount
5. Predict the output of the following programs :
a. count = 0
while count<10:
print (‘Hello’)
count += 1
b. keepgoing = True
x = 100
while keepgoing:
print(x)
x = x-10
if x<50:
keepgoing = false
c. for z in range(-500, 500, 100):
print(z)
d. for x in ‘lamp’:
print(str.upper(x))
6. Find the error in the following code. Correct the code and write the output.
s1 = ‘must’
s2 = try
n1 = 10
n2 = 3
print(s1+s2)
print(s2*n2)
print(s1+n1)
print(s2*s1)
7. Consider the following code:
inp = input(“Please enter a string”)
while len(inp) < = 4:
if inp[-1] == ‘z’ :
inp = inp[0:3] + ‘c’
elif ‘a’ in inp:
inp = inp[0] + ‘bb’
elif not int(inp[0]):
inp = ‘1’+inp[1:] + ‘z’
else:
inp = inp + ‘*’
print(inp)
What will be the output produced if the input is i) ‘1bzz’ ii) ‘1a’ iii) ‘abc’ iv) ‘0xy’
v) ‘xyz’

8. Write a program that reads a string and checks whether it is a palindrome or not.
9. How are lists different from strings when both are sequences?
10. What is sorting? Write a program that uses bubble sort to sort a list of integers.
11. Write a method to display the elements of list thrice if it is a number and display the
element terminated with '#' if it is not a number.
For example, if the content of list is as follows
Lst = [‘41’,’DROND’,’GIRIRAJ’,’13’,’ZARA’]
The output should be
414141
DROND#
GIRIRAJ#
131313
ZARA#

12. What is the difference between the formal parameters and actual parameters? What
are their alternative names?
13. Following code intends to swap the values of two variables through a function, but
upon running the code, the output shows that the values are swapped inside the
switch() function but back again in the main program, the variables remain un-
swapped. What could be the reason? Suggest a fix.
def switch(x, y):
x, y=y, x
print(“inside switch:”, end=’ ‘)
print(“x = ”, x, “y = ”, y)
x=5
y=7
print(“x = ”, x, “y = ”, y)
switch(x, y)
print(“x = ”, x, “y = ”, y)
14. Write a function that takes a positive integer and returns the one’s position digit of
the integer.
15. Find the error. Correct the code and predict output.
def Tot(Number)
Sum =0
for c in Range(1, Number+1)
Sum +=c
RETURN Sum
print(Tot[3])
print(Tot[6])
16. Consider the code below and answer the questions that follow:
def multiply(number1, number2):
ans = number1*number2
return(ans)
print(number1, ‘times’, number2, ‘ = ’, ans)
output = multiply(5,5)
i) When the code above is executed, what prints out?
ii) What is the value of variable output after code is excecuted?
17. Write a function namely nth Root () that receives two parameters x and n and
returns nth root of x. The default value of n is 2.
18. What is the utility of built-in function help()?
19. What are the possible outcome(s) of the following code? Also specify the maximum
and minimum values that can be assigned to variable NUMBER.
STR = “CBSEONLINE”
NUMBER = random.randint(0, 3)
N=9
while STR[N] != ‘L’:
print(STR[N] + STR[NUMBER]+’#’, end=’ ‘)
NUMBER += 1
N = N-1
i) ES#NE#IO#
ii) LE#NO#ON#
iii) NS#IE#LO#
iv) EC#NB#IS#
20. What is the difference between read() and readlines() function?
21. The file new.txt contains the following

Better than heaven or arcadia


I love thee, oh my India!
And thy love I shall give
To every brother Nation that lives.

Considering the given file what output will be produced by the following code-

obj1 = open(“New.txt”, “r”)


s1 = obj1.readline()
s2 = obj2.readline()
s3 = obj2.readline()
s4 = obj1.read(15)
print(s4)
obj1.close()
22. A text file contains alphanumeric text (say an.txt). Write a program that reads this
text file and prints only the numbers or digits from the file.
23. What is the following code doing?
file = open(“contacts.csv”,’a’)
name = input(“Please enter name.”)
phno = input(“Please enter phone number”)
file.write(name + “,” + phno + “\n”)
24. Write code to open file created in previous question and print it in following form-
Name : <name> Phone : <phone number>
25. Write a program to count the words “to” and “the” present in a text file “Article.txt”.
26. What are base case and recursive case? What is their role in a recursive program?
27. When does infinite recursion occur?
28. Figure out the error in the following recursive code of factorial-
def fact(n):
if n == 0 :
return 1
else:
n*fact(n-1)
#__main__
print(fact(n))
29. Write recursive code to compute and print sum of squares of n numbers. Value of n
is passed as a parameter.
30. Why are recursive functions considered slower than their iterative counterparts?
31. Predict the output of following code –
def express(x, n):
if n == 0 :
return 1
elif n % 2 == 0:
return express(x*x, n/2)
else:
return x * express(x, n-1)
express(2,5)
32. Consider the following infix expression
P = -a +b * c ^(d*e)/f
where ^ denotes exponentiation, and / integer division. Translate P into its
equivalent postfix expression using the following set of priorities.

( 0
+-) 1
unary - * / 2
^ 4
33. Write a program to implement a stack for book-details i.e. book-no and book-name.
That is, now each item node of the stack contains two types of information – a book-
no and its name. Implement Push and display operations using a menu driven
program.
34. Write the full form of the following –
a. NIC
b. MAC
c. FTP
d. TCP/IP
e. OSI
f. VoIP
g. SSH
h. HTTPS
i. RFID
j. IoT
k. NFC
l. URI
m. POP
n. IMAP
o. SMTP
35. What is the difference between hub, switch and router?
36. What are the security concerns related to IoT?
37. What is a collision in a network? How does it impact the performance of a network?
38. What are the steps followed in checksum generator?
39. What is a tracert or traceroute command?
40. What is HTTPS? How does it work?
41. What are ACK, CTS and RTS signals?
42. What is the use of Whois networking command?
43. Consider the following network map showing how routers of various networks are
connected.

B C

F
A

D E

Prepare routing tables for any three routers of your choice.


AUTUMN BREAK ASSIGNMENT II
XII COMPUTER SCIENCE
1. Why is Boolean considered a subtype of integers in Python?
2. How can an integer be represented as octal, binary and hexadecimal in Python?
3. Explain the use of pass statement with a suitable example.
4. Write a program in Python that reads a date as an integer in the format MMDDYYYY.
The program should call a function that prints the date in the format <Month Name>
<day>, <year>.
Sample run:
Enter date – 12252019
December 25, 2019
5. Can you use lists as keys in a dictionary? State reason.
6. If a is (1, 2, 3)
a. what is the difference between a*3 and (a,a,a) ?
b. is a*3 equivalent to a+a+a?
7. Write a program that generates 4 terms of an AP by providing initial and step values to
a function that returns first four terms of the series.
8. Write a function that takes two numbers and generates a random number from that
range. Using this function, the main program should be able to print three numbers
randomly.
9. Write a program that generates a series using a function which takes first and last
values of the series and then generates four terms that are equidistant e.g., if two
numbers passed are 1 and 7 then function returns 1 3 5 7.
10. The random() function generates a random floating point number in the range 0.0 to
1.0 and randint(a, b) function generated random integer between range a and b. To
generate random numbers between range a to b using random(), following formula is
used:
math.random()*(b-a)+a

Now if we have following two statements


i. int((math.random()*(b-a) + a))
ii. math.randint(a, b)
Can you say above two statements are now producing random integers from the same
range? Why?
11. What would be the output produced by the following code :
import math
import random
print(math.ceil(random.random()))
Justify your answer.
12. Write a function in Python to count and display the number of lines starting with
alphabet A present in a text file lines.txt. For example if thhe file contains the following
lines -
A boy is playing there.
There is a playground.
An aeroplane is in the sky.
Alphabets and numbers are allowed in password.

the function should display the output 3.


13. Consider the following function that takes two positive integer parameters x and y.
Answer the following questions based on the code below.

def cmpt(a, b):


if a > 1:
if a % b == 0 :
print(b, end = ‘ ‘)
cmpt(int(a/b), b)
else:
cmpt(a, b + 1)
a. What will be printed by the function call cmpt(24,2) ?
b. What will be printed by the function call cmpt(84,2) ?
c. State in one line what is cmpt() trying to calculate?
14. Write recursive code to compute greatest common divisor of two numbers.
15. Consider the following Python function fn(), that takes an integer n as parameter and
works recursively as follows :
def fn (n) :
print(n, end = ‘ ‘ )
if n > 3:
return n
else:
return fn(n//2) – fn(n//3)
What will be the result produced by the following function calls –
a. fn(12) b. fn(10) c. fn(7)
16. Write a menu-driven program to perform insert and delete operations on a Queue
containing Members details as given in the following definition of itemnode –
MemberNo integer
MemberName String
Age integer
17. Consider an empty stack of integers. Let the numbers 1,2,3,4,5,6 be pushed on to this
stack only in the order they appeared from left to right. Let S indicate a push and X
indicate a pop operation. Can they be outputted in to the order 325641 and order
154623?
(Hint. SSSSSSXXXXXX outputs 654321)

You might also like