Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

LAB03

Total questions: 7

Worksheet time: 7mins

Name
Class
Date
1.

What are the contents of names after executing the following code fragment?

names = ["Fritz"]

names.insert(1, "Ann")

names.insert(0, "Sue")

names.pop(2)

names.append("Lee")

a)

['Fritz', 'Ann', 'Lee']

b)

['Sue', 'Fritz', 'Lee']

c)

['Lee', 'Sue', 'Fritz']

d)

['Fritz', 'Sue', 'Lee']

2.

What will be the output of the following code fragment?

a = [2, 2, 2, 2]

b = [1, 1, 1]

c = a+b

print(c)

a)

This code will generate an error

b)

[3, 3, 3, 2]

c)

[1, 1, 1, 2, 2, 2, 2]

d)

[2, 3, 3, 3]

e)

[2, 2, 2, 2, 1, 1, 1]

3.

What will be output of the following python code?

string1 = "ICS##104-Computer##Science##"

index = string1[string1.count("##")]

print(index)

a)

Error

b)

3

c)

#

d)

S

4.

phrase = "212-ICS-Midterm"

d= len(phrase)

a = int(phrase[2]) -1

b = phrase.find('-')

c = phrase[8:]

print(d,a,b,c)

(a)  

5.

Which of the following statements create a dictionary?

a)

d = {}

b)

d = {"Ali":25, "Ahmed":22}

c)

d=[]

d)

d = {25:"Ali", 22:"Ahmed"}

6.

What is the output after executing the following python code?

values = { "F": 55, "M": 31, "B": 16, "C": -2 }

print(values[1])

a)

Error

b)

'F': 55

c)

31

d)

'M': 31

7.

What will be the output of the following Python code?

s={3, 4, 4, 3, 10, 10}

s.add(4)

s.remove(10)

print(len(s))

a)

4

b)

3

c)

2

d)

Error