wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CSE 102 Exam 2 Practice

Total questions: 15

Worksheet time: 10mins

Name
Class
Date
1.

Which of the following methods is used to add an element to the end of a list in Python? (And only to the end of the list)

a)

list.insert()

b)

`list.append()`

c)

`list.add()`

d)

`list.extend()`

2.

What will be the output of the code snippet?

a)

Hello

b)

World

c)

World!

d)

, Worl

3.

How many times will i be printed?

a)

4 times

b)

5 times

c)

6 times

d)

0 times

4.

Which option below converts the while loop to a for loop?

a)

b)

c)

d)

5.

Which of the following is true about nested loops?

a)

Only for loops can be nested.

b)

Only while loops can be nested.

c)

Both for and while loops can be nested.

d)

Nested loops are not allowed in Python.

6.

What is the output of the code?

a)

0:1

0:2

0:3

1:1

1:2

1:3

b)

1:0

1:1

2:0

2:1

c)

1:0

1:1

1:2

2:0

2:1

2:2

3:0

3:1

3:2

d)

0:1

1:1

0:2

1:2

7.

Which loop is more suitable for iterating over a list when the number of iterations is known?

a)

for loop

b)

while loop

c)

do-while loop

d)

foreach loop

8.

Which loop is better situated for an unknown number of iterations?

a)

While

b)

For

9.

What will be the output of the code?

a)

[2,4,6,8,10]

b)

[1,1,2,2,3,3,4,4,5,5]

c)

[1,2,3,4,5]

d)

[1,2,3,4,5,1,2,3,4,5]

10.

Which of the following is a valid way to create a list in Python? Select all that apply.

a)

myList = list()

b)

list = {}

c)

myList = []

d)

myList = <>

11.

What will be the output of the code?

a)

PYTHON

b)

python

c)

Python

d)

pYTHON

12.

Which of the following is not a valid string operation in Python?

a)

Concatenation

b)

Slicing

c)

Multiplication

d)

Division

13.

What is the first line of output if the user types "PyThon" after the initial input prompt?

a)

Welcome

b)

Try again!

c)

Error

d)

Enter your password

14.

Given the list of lists, how would you access the number 3?

myList = [[1, 2], [3, 4], [5, 6]]

a)

myList[[2]]

b)

myList[1,0]

c)

myList[1][0]

d)

myList[2][1]

15.

What is the output from the code?

a)

230.4480 is a floating point value.

b)

230.448 is a floating point value.

c)

230.450 is a floating point value

d)

0230.448 is a floating point value.