wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

PYTHON PROGRAMMING - FINAL EXAM REVIEW

Total questions: 46

Worksheet time: 23mins

Name
Class
Date
1.

1. What does type(3.55) return?

a)

str

b)

int

c)

float

d)

All of these

2.

1. How do you know if you have written your code correctly and there are no errors?

a)

Print your code

b)

Debug your code

c)

View your code

d)

Reset your code

3.

1. Which contains only integers? (ignore the commas)

a)

3, 2, 1, *, +, =, -

b)

Q, W, E, R, T, Y, a, s, d, f

c)

-2, -1, -0.5, 0, 0.5, 1, 2

d)

1, 2, 0, -3, 2, -5

4.

The input() function in Python returns user input as a string.

a)

True

b)

False

c)

I'm not interested in guessing

5.

name = "skye homsi"

name1 = name.title()

name2 = name1.swapcase()

print(name2)


What is the output from the above code?

a)

"skye homsi"

b)

"sKYE hOMSI"

c)

"Skye Homsi"

d)

"SKYE HOMSI"

6.

1.name = input("enter your name")

2. print(name, "your score is", score)

3. score = 199

Order the above numbered code lines into the proper sequence:

a)

3,1,2

b)

1,2,3

c)

1,3,2

d)

3,2,1

7.

vehicleType = "Truck"

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

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

else:

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

What is the output from running the above code?

a)

“False”

b)

"True"

c)

"Truck does not start with "P""

d)

Truck starts with "P""

8.

1. A function with 2 integer parameters could start with which definition?

a)

showName.run()

b)

showName()

c)

run showName

d)

open(showName)

9.

def addNumbers(num1, num2 = 10):

return num1 + num2


Choose the correct output of calling the function above using the following code:


print(addNumbers(100))

a)

an error

b)

100

c)

200

d)

110

10.

num_1 = 3

num_2 = "8"

What is the minimum code to mathematically add num_1 to num_2?

a)

int(num_1) + int(num_2)

b)

num_1 + int(num_2)

c)

num_1 + str(num_2)

d)

int(num_1) + str(num_2)

11.

size_num = "8 9 10"


size = "8" # user input


if size.isdigit() == False:

print("Invalid: size should only use digits")

elif int(size) < 8:

print("size is too low")

elif size in size_num:

print("size is recorded")

else:

print("size is too high")


What is the output from running the above code?

a)

"size is recorded"

b)

"Invalid: size should only use digits"

c)

"size is too high"

d)

"size is too low"

12.

x = 3

y = 4

calculation = x*y

print(calculation)


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

a)

12.0

b)

9

c)

12

d)

9.0

13.

if True:

if False:

print("Banana")

else:

print("Apple")

else:

if True:

print("Dates")

else:

print("Corn")


What is the output of the above code?

a)

"Dates"

b)

"Banana"

c)

"Corn"

d)

"Apple"

14.

Escape sequences start with a backslash (\).

a)

True

b)

False

15.

Hello


World!


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

a)

print("Hello\nWorld!")

b)

print("Hello\tWorld!")

c)

print("Hello World!")

d)

print("Hello\pWorld!")

16.

x = 0

while True:

if x < 10:


print('run forever')

x += 1


else:


break


What is the output from running the above code most like?

a)

"run forever" (9 times)

b)

No Output

c)

"run forever" (10 times)

d)

"run forever" (11 times)

17.

def ignore_case(name):

answer = ""

while answer.isalpha() == False:

answer = input("enter last name: ")

return answer.lower() ==

name.lower()


When will the ignore_case function exit the while loop?

a)

When answer == name

b)

When answer.lower() == name.lower()

c)

When a digit is entered at the input prompt

d)

When only letters are entered at the input prompt

18.

Which choice will print the first half of the word "Consequences", given the following variable declaration?


word = "Consequences"

a)

print(word[7:1])

b)

print(word[:6])

c)

print(word[1:7])

d)

print(word[6:])

19.

In the for loop below, the variable "word" is an arbitrary variable name. Any valid variable name can be used since its value is assigned only within this loop.


for letter in word:

print(letter)

a)

False

b)

True

20.

Which choice best represents the output of the following code?


student_name = "iteration"

new_word = ""


for letter in student_name[:3]:

new_word += letter

print(new_word)

a)

"iter"

b)

"ite"

c)

"ation"

d)

"ration"

21.

The .count() string method returns the number of times a for/in loop iterates

a)

True

b)

False

22.

1. Python cannot display quotes in strings using print().

a)

False

b)

True

23.

"Hello".isalpha()


What is the output of the above code?

a)

True

b)

Error

c)

False

d)

Hello

24.

answer = input("enter your answer: ")

print("You entered " + answer)


If user input is 38, what is the output of the above code?

a)

You entered 38

b)

TypeError

c)

SyntaxError

d)

You entered enter your answer

25.

What does type("Hello World!") return?

a)

int

b)

float

c)

str

d)

All the above

26.

Choose the correct statement.

a)

The same variable in Python can be represented in either upper or lower case

b)

Variables only represent strings in Python.

c)

Variables in Python can be initialized using the equals sign (=).

d)

New variables always start out as zero.

27.

The type() function is used to change from one data type to another.

a)

True

b)

False

28.

What does type(1024) return?

a)

int

b)

float

c)

str

d)

All of these

29.

Choose the correct statement.

a)

Variables are updated in Python using the keyword "new".

b)

A variable name in Python cannot contain numbers.

c)

Variable values in Python can change type, from integer to string

d)

A variable value in Python cannot be updated.

30.

"Hello, world!" is a specialized program used specifically for Python.

a)

False

b)

True

31.

In Python, we can use the "+" operator to add numbers, but not to add strings.

a)

True

b)

False

32.

1. PriNt("Hello World!") will not output the message "Hello World!".


What will it result in?

a)

NameError

b)

TypeError

c)

SyntaxError

d)

All of these

33.

Which is a valid Python code comment?

a)

[comment] comments can provide use instructions for other developers.

b)

(comment) warnings can be placed in comments.

c)

/comments make code easier to update.

d)

# use comments to describe the function of code.

34.

What does the Python code: score = 3 + "45" result in?

a)

345

b)

type()

c)

TypeError

d)

48

35.

answer = input("enter your answer: ") print(10 + answer)


If user input is 38, what is the output of the above code?

a)

10answer

b)

TypeError

c)

1038

d)

48

36.

Which code formats the string "Green" to "GREEN"?

a)

.isupper()

b)

.istitle()

c)

.upper()

d)

.capitalize().

37.

def addNum(num1 = 10):

return num1 + num1


Choose the correct output of calling the function above using the following code:


print(addNum(100))

a)

100

b)

200

c)

20

d)

An error

38.

name = "SKYE HOMSI"

print("y" in name.lower())


What is the output from the above code?

a)

"skye homsi"

b)

3

c)

False

d)

True

39.

def lowCase(wordsIn):

return wordsIn.lower()


Choose the correct output of calling the function above using the following code:


wordsLower = lowCase("Return THIS lower")

print(wordsLower)

a)

"return this lower"

b)

"Return THIS lower"

c)

An error

d)

No Output

40.

Function names cannot begin with a number as the first character.

a)

True

b)

False

41.

def addNum(num1 = 10): print(num1 + num1)


Choose the correct output of calling the above function using the following code:


addNum()

a)

An error

b)

0

c)

20

d)

10

42.

1. greet(name)

2. name = input("enter your name: ")

3. greet(name)

4. def greet(person): u

5. print("Hi,", person)

6. greet(name)


Which line or lines need to be removed from the above code so the program prints a greeting without error?

a)

line 1 only

b)

line 1 and 3

c)

line 3 only

d)

lines 1 and 2

43.

name = "Tobias"

print(name == "Alton")


What is the output from running the above code?

a)

"Tobias = Alton"

b)

False

c)

"Alton"

d)

True

44.

day = "monday"


if day.capitalize() == "Monday":

print("Start the week!")

else:

pass


What is the output from running the above code?

a)

No Output

b)

True

c)

"Start the week!"

d)

False

45.

x = 3

y = "3"

# get_diff takes an int and a str

def get_diff(xint, ystr):

# <function code needed here>


if y.isdigit() == False:

print('"y" is not an integer string')

elif get_diff(x,y) == 0:

print('x equal to y')

else:

print('x is NOT equal to y')


To make this program work, printing "x equal to y", choose the best code to replace the above comment "# <function code needed here> " in the get_diff function.

a)

return str(ystr) - in(xint)

b)

return int(ystr) – xint

c)

return ystr – x

d)

a. return int(xint) – y

46.

x = 3

y = 3

calculation = x/y

print(calculation)


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

a)

1

b)

9.0

c)

9

d)

1.0