wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Domain

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Given the following string:

h = "Hello", which code results in an error?

a)

print (h)

b)

print(h.lower())

c)

h = 's'

d)

print(h+1)

2.

What is the output of the following code?

a)

Good Bye

b)

Welcome

c)

An error message

d)

None of the above

3.

What does the input() function return?

a)

an integer value

b)

a string value

c)

a float value

d)

all of the above

4.

What is the value of x after the following code is run?

a)

19

b)

20

c)

21

d)

22

5.

Which statements evaluate True and without errors?

a)

"unbothered".isupper()

b)

"Monroe High School".istitle()

c)

5.isdigit()

d)

"animal".islower()

6.

Which statement sets the variable t to a value of "Total Credits: 25"?

a)

t = "Total Credits:" + 25

b)

t = "Total Credits:" + str(25)

c)

t = input("Total Credits:" + str(25))

d)

print("Total Credits", "25")

7.

What is "print" used for?

a)

To input

b)

To make strings

c)

To display output

d)

Non of the above

8.

What is the output of the following code?

print("He said, \"I'm coming to school tomorrow.\"")

a)

"He said, I'm coming to school tomorrow."

b)

'He said, "I'm coming to school tomorrow."'

c)

He said, \I'm coming to school tomorrow.\

d)

He said, "I'm coming to school tomorrow."

9.

Which operator can be used to combine two strings?

a)

+

b)

-

c)

!

d)

/

10.

If book_title = "Gone with the Wind" which code will return True

a)

"G" in book_title

b)

book_title.startswith("g")

c)

print("g", book_title)

d)

book.title.has("g"

11.

What are the advantages of creating and using functions in code? (Choose all that apply)

a)

code reuse

b)

Boolean string testing

c)

faster running code

d)

easier testing

12.

Which is a python function?

a)

input()

b)

"Hello Students"

c)

x = 4

d)

def

13.

Analyze the following code and choose the most correct statement:

a)

The program runs and displays "It is even!"

b)

The program runs, but displays nothing.

c)

The program has a Syntax Error in line 1: even = false

d)

The program has an error in line 2: if Even == True

14.

Which of the following is a valid Python comment structure?

a)

#comment

b)
  • comment
c)

/*comment*/

d)

/#comment#/

15.

For the code x>= y which x and y values evaluate True?

a)

x = 5, y = 6

b)

x = "b", y = "B"

c)

x = 0, y = 1

d)

x = "Z", y = "a"

16.

Which is a Python method of getting numeric input that can be used in math?

a)

num1 = get_int

b)

num1 = str(input("enter a number"))

c)

num1= (input("enter a number")).float()

d)

num1 = int(input("enter a number"))

17.

Which is not a possible "infinity/infinite" loop?

a)

while True:

b)

while 1 > 0:

c)

while 1 != 0:

d)

while 0 >1:

18.

Which of the following statement is true?

a)

Python variables are case sensitive

b)

Python variables have a fixed, unchangeable data type

c)

Python variable names start with a number, letter or underscore

d)

All the above

19.

What will be displayed by the following code?

a)

Hello Hello Hello Hello

b)

Hello Hello Hello Hello Hello Hello Hello Hello

c)

Hello Hello Hello Hello Hello Hello Hello

d)

Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello

20.

What is the order of precedence (from first to last ) of the math operators?

a)

+, -,/,*

b)

*,+,-,/

c)

*,/,+,-

d)

*,+,/,-