Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Fundamentals

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

Analyze the following code.


count = 0

while count < 100:

# Point A

print("Welcome to Python!")

count += 1

# Point B


# Point C

a)

count < 100 is always True at Point A

b)

count < 100 is always True at Point B

c)

count < 100 is always False at Point B

d)

count < 100 is always True at Point C

2.

How many times will the following code print "Welcome to Python"?


count = 0

while count < 10:

print("Welcome to Python")

a)

9

b)

10

c)

11

d)

infinite number of times

3.

What will be displayed when the following code is executed?


number = 6

while number > 0:

number -= 3

print(number, end = ' ')

a)

6 3 0

b)

6 3

c)

3 0

d)

3 0 -3

4.

The function range(5) return a sequence ______________.

a)

1, 2, 3, 4, 5

b)

0, 1, 2, 3, 4, 5

c)

1, 2, 3, 4

d)

0, 1, 2, 3, 4

5.

A Python line comment begins with ________.

a)

//

b)

/*

c)

#

d)

$$

6.

To start Python from the command prompt, use the command _______

a)

execute python

b)

run python

c)

python

d)

go python

7.

What will be displayed by the following code?


print("A", end = ' ')

print("B", end = ' ')

print("C", end = ' ')

print("D", end = ' ')

a)

ABCD

b)

A, B, C, D

c)

A B C D

d)

A, B, C, D will be displayed on four lines

8.

Suppose s = "Welcome", what is type(s)?

a)

str

b)

int

c)

float

d)

String

9.

Given a string s = "Welcome", which of the following code is incorrect?

hint: a str object is immutable!

a)

print(s[0])

b)

s[1] = 'r'

c)

print(s.strip())

d)

print(s.lower())

10.

What is the output of the following code?


x = 0

while x < 4:

x = x + 1


print("x is", x)

a)

x is 1

b)

x is 2

c)

x is 3

d)

x is 4

11.

Analyze the following statement:


sum = 0

for d in range(0, 10, 0.1):

sum += sum + d

a)

The program has a syntax error because the range function cannot have three arguments.

b)

The program has a syntax error because the arguments in the range must be integers

c)

The program runs in an infinite loop

d)

The program runs fine

12.

Which of the following loops prints "Welcome to Python" 10 times?


A:

for count in range(1, 10):

print("Welcome to Python")


B:

for count in range(0, 10):

print("Welcome to Python")


C:

for count in range(1, 11):

print("Welcome to Python")


D:

for count in range(1, 12):

print("Welcome to Python")

a)

BD

b)

ABC

c)

AC

d)

BC