wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python study guide

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the result of not setting the value of the year attribute of a date object?

a)

The year defaults to 9999.

b)

The object is invalid.

c)

Cheese

d)

23

2.

Which statement about the datetime.datetime data type is true?

a)

All date variables are required.

b)

All time variables are required.

c)

Mr. Isenhour is the best teacher

d)

43

3.

Which function displays a date object in the form Monday, January 01, 2018?

a)

.strftime("%A, %B %d, %Y")

b)

.strftme("%A, %B %d, %Y")

c)

.srftime("%A, %B %d, %Y")

d)

.stftime("%A, %B %d, %Y")

4.

Python cannot display quotes in strings using print().

a)

True

b)

False

5.

Escape sequences start with a backslash (\).

a)

True

b)

False

6.

Hello

World!


What is the best choice of code to create the output shown above?

a)

print("Hello World!")

b)

print("Hello\tWorld!")

c)

print("Hello\pWorld!")

d)

print("Hello\nWorld!")

7.

\\\\

What is the best choice of code to create the output shown above?

a)

69

b)

Mouse

c)

print("\\\\\\\\")

d)

print(\\\\)

8.

It's

Python Time!

Choose the code that will not create the output shown above.

a)

print("It's" + "\nPython Time!")

b)

print("It's" + "\nPython Time!")

c)

print("It's" + "Python Time!")

d)

print("It's" + "\nPython Time!")

9.

The \t escape sequence moves the text to the right approximately ____ spaces in Python.

a)

3

b)

56

c)

498523948

d)

3234456

10.

What is the best estimate for the output of the code below?

x = 3

y = 3

calculation = x/y

print(calculation)

a)

1.0

b)

9

c)

9.0

d)

3

11.

Looking at the code below, which code example properly calls the function and returns a calculation?

def subtotal(orderAmt, salesTax):

if orderAmt > 0:

subtotal = int(orderAmt) * (1 + float(salesTax))

return subtotal

else:

return "Invalid order amount."

a)

orderTotal = def subtotal(500, 0.07)

b)

orderTotal = subtotal(500, 0.07)

c)

subtotal(500, 0.07)

d)

call subtotal(500, 0.07)

12.

Given x = 9, which line of code will evaluate False?

a)

x = 3

b)

x<3

c)

x==9

d)

3

13.

What is the output from running the code below?

vehicleType = "Truck"


if vehicleType.upper().startswith("P"):

print(vehicleType, 'starts with "P"')

else:

print(vehicleType, 'does not start with "P"')

a)

"Truck does not start with "P""

b)

"Truck starts with "P""

c)

"False"

d)

SyntaxError

14.

What is the output from running the code below?

hotPlate = True


if hotPlate:

print("Be careful, hot plate!")

else:

print("The plate is ready.")

a)

Invalid Code

b)

"The plate is ready."

c)

psdmsomccomscms

d)

"Be careful, hot plate!"

15.

What is the best estimate for the output of the code below?

x = 3

y = 4

calculation = x * y

print(calculation)

a)

9.0

b)

9

c)

12

d)

12.0

16.

In Python string comparisons, lower case "a" is less than upper case "A".

a)

True

b)

False

17.

Which method can be used to return a string in upper case letters?

a)

upper()

b)

toUpperCase()

c)

toUpperCase()

d)

upperCase()

18.

What is the best estimate for the output of the code below?

calculation = 5 + 15 / 5 + 3 * 2 - 1

print(calculation)

a)

13.0

b)

9.0

c)

13

d)

9

19.

What is the output from running the code below?

name = "alton"

print(name == "Alton")

a)

True

b)

Alton

c)

False

d)

Tobias = Alton

20.

Complete the code example to build a function that does the following:

Name is calcSubtotalThe function takes an amount and sales tax rate and calculates a subtotal The new subtotal is returned Name is calcSubtotal The function takes an amount and sales tax rate and calculates a subtotal The new subtotal is returned

(A) ___________________ (B) __________________

subtotal = amount * (1+salesTaxRate)

(C) ___________________

a)

(A) def calcSubtotal (B) (amount, salesTaxRate): (C) return subtotal

b)

(A) def calcSubtotal (B) () (C) return subtotal

c)

(A) function calcSubtotal (B) (amount,salesTaxRate):

d)

(A) calcSubtotal (B) (amount, salesTaxRate) (C) return