wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Final Assessment

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which of the following command is used to open a file “c:\temp.txt” in read-mode only?

a)

infile = open(“c:\temp.txt”, “r”)

b)

infile = open(“c:\\temp.txt”, “r”)

c)

infile = open(file = “c:\temp.txt”, “r+”)

d)

infile = open(file = “c:\\temp.txt”, “r+”)

2.

Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?

a)

file.read(n)

b)

n = file.read()

c)

file.readline(n)

d)

file.readlines()

3.

what will be the output of following code:


list = [ 'Tech', 404, 3.03, 'Beamers', 33.3 ]

print (list[1:3])

a)

[ 'Tech', 404, 3.03, 'Beamers', 33.3 ]

b)

['Tech', 'Beamers']

c)

[404, 3.03]

d)

Error

4.

Which of the following functions print the output to the console?

a)

output()

b)

print()

c)

echo

d)

print.show()

5.

What gets printed as the output of the below code?

x = True

y = False

z = False

if not x or y:

print 1

elif not x or not y and z:

print 2

elif not x or y or not y and x:

print 3

else:

print 4

a)

4

b)

3

c)

2

d)

1

6.

What is the correct file extension for Python files?

a)

pt

b)

txt

c)

python

d)

py

7.

What is the correct syntax to output the type of a variable or object in Python?

a)

print(type(x))

b)

print(typeof(x))

c)

print(typein(x))

d)

print(value(x))

8.

What is the correct way to create a function in Python?

a)

function myFunction()

b)

define Func()

c)

function()

d)

def myFunction()

9.

Which operator is used to multiply numbers?

a)

*

b)

x

c)

mul

d)

#

10.

Which of these collections defines a LIST?

a)

["Apple", "Banana", "cherry"]

b)

{"Apple", "Banana", "cherry"}

c)

"Apple", "Banana", "cherry"

d)

["Apple": "Banana", "cherry":"Apple"]