0% found this document useful (0 votes)
151 views3 pages

Practice Paper 2

The document contains 25 questions related to Python programming concepts like data types (dictionaries, tuples, strings), operators, functions and more. It asks to find errors in code snippets, determine outputs, write Python statements, and identify Python concepts.

Uploaded by

Ritik Kumar
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)
151 views3 pages

Practice Paper 2

The document contains 25 questions related to Python programming concepts like data types (dictionaries, tuples, strings), operators, functions and more. It asks to find errors in code snippets, determine outputs, write Python statements, and identify Python concepts.

Uploaded by

Ritik Kumar
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/ 3

1.

Find error, underline them and rewrite the same after correcting the following
code:
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 int(i, ‘\t’ , ‘d1 [i]’)

2. What output produced by the following code?


>>> Alist = [1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> print (Alist[::3])

3. A tuple is declared as
>>> T = (2, 5, 6, 9, 8)
>>> sum(T)

4. Write a statement in Python to declare a dictionary whose keys are 1, 2, 3 and the
values are Monday, Tuesday and Wednesday respectively.

5. A tuple is declared as
T = (23, 8.6, 'hello', 41, 'x')
What will be the value of T[:1:-1]?

6. What is the output of the following string operation?


st = "Computer Sciences 12"
print(st.isalnum())

7. Write a statement in python to declare a dictionary D with 100 keys 0, 1, .., 99 each
having values as 200.

8. You have the following code segment:


String1 = "my"
String2 = "work"
print (String1 + String2.upper())
What is the output of this code?

9. What is the output of the following?


dry = {0:'a', 1:'b', 2:'c'}
for x, y in dry.items():
print(x, y, end =' ')
10. What will be the output of the following statements?
>>> 2 < 3
>>> True + 4

11. Find the output of the following expression:


(5<10) and (10<5) or (3<18)and not 8<18

12. Name the Python Library modules which need to be imported to invoke the
following functions:
a) ceil() b) randrange()

13. Which of the following statements will create a tuple ?


(a) Tp1 = (“a”, “b”) (b) Tp1= (3) * 3 (c) Tp1[2] = (“a”, “b”)
(d) None of these

14. Find the output of the following:


>>> S = 1, (2, 3, 4), 5, (6,7)
>>> len(S)

15. Which of the following are Keywords in Python?


a) break b) check c) range d) while

16. Give the output of the following code:


L = [ 1, 2, 3, 4, 5, 6, 7]
B=L
B[3:5] = 90, 34
print(L)

17. A tuple is declared as T = (1, 2), (1, 2, 4), (5, 3) What will be the value of min(T) ?

18. Which of the following functions generates an integer?


a) uniform( ) b) randint( ) c) random( ) d) None

19. What is the output of the following code?


for i in range(-3, 4, 2):
print(i, end = '$')

20. Identify the data type of X:


X = tuple(list( (1, 2, 3, 4, 5) ) )

21. What will be output of following:


d = {1 : "SUM", 2 : "DIFF", 3 : "PROD"}
for i in d:
print (i)

22. What will be the result of the following statements?


a) bool(int(‘0’)) b) type(“hello”)
23. If X = ”Happy Sunday” what will be the output of print(X[:2], X[:-2], X[-2:])

24. Consider the following statement.


Dict = { “Teena”:18, ”Riya”:12, “Aliya”:22}
How will you remove “Riya” from Dict?

25. Find the length of the following tuple:


a) tuple1 = ((1, 2), (3, 4.15, 5.15), (7, 8, 12, 15))
b) T = ((1, 2), 3, 4.15, 5.15, (7, 8, 12, 15))
c) M = ((1, 2), 3, 4.15, 5.15, (7, 8,(5, 6),12,15))

You might also like