Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

COSC 1 Final

Total questions: 15

Worksheet time: 45mins

Name
Class
Date
1.

Which of the following best describes how Python statements are executed?

a)

All at once

b)

One line at a time: top to bottom

c)

One line at a time: bottom to top

d)

In batches of 10 lines at a time

2.

Which of these print statements will not give you an error?

a)

print("hello world")

b)

print=("hello world")

c)

print(int("hello world)

d)

print "hello world"

3.

What is the purpose of leaving comments in your source code?

a)

To make code easier for humans to understand

b)

So python gets a break when running the code

c)

To slow down the speed of the code

d)

All of these are true

4.

Which of the following variable names are invalid?

a)

123Gaming

b)

GamingpC

c)

all of them

d)

Gaming_123

5.

Which of the following values is not a valid integer?

a)

5

b)

51000

c)

-100

d)

-12.3

6.

Which of the following is not a valid floating point number?

a)

"Floating Point"

b)

5.554

c)

-12.3

d)

All of these are valid

7.

If you concatenate strings together with the plus sign (+), which of the following statements is true?

a)

No spaces will be added to separate the parts within the output string

b)

A space will be automatically added to separate each part within the output string

c)

The resulting string must be less than 128 characters in length

d)

Only the longer input string will appear in the output string

8.

Which of the following statements will convert a string stored in "inputResults" to an integer variable called "age"?

a)

age.int(inputResults)

b)

age = int(inputResults)

c)

inputResults = parse(age)

d)

age = inputResults.parse()

9.

If "numGrapes" is equal to 10, which of the following expressions will produce a False result?

a)

numGrapes != 10

b)

All of these are False

c)

numGrapes < 9

d)

numGrapes >= 11

10.

If food="milkshake" and flavor="chocolate", what is the result of the following logical expression?

(food == "milkshake" and flavor == "vanilla")

a)

Milkshake

b)

Vanilla

c)

False

d)

True

11.

If you want to print "Password verified" when the user guesses the matching password, what is wrong with the following code?

password = "SECRET"

guess = input("What's the password? ")

if (guess != password):

print("Password verified")

else:

print("Access denied")

a)

It will show a syntax error

b)

It will print the opposite of what you want due to a logical error

c)

Nothing is wrong; it will do exactly what you want

d)

It will throw a runtime exception

12.

Which function do we suggest using to create your program trace statements?

a)

breakpoint()

b)

print()

c)

trace()

d)

display()

13.

What is displayed on the screen when the following code runs?

esports = ["Donkey Kong", "Galaga", "Pac Man"]

if ("Galaga" in esports):

print("Found it")

else:

print("Not here")

a)

Nothing is printed out

b)

Found it

c)

Not here

d)

Both "Found it" and "Not here"

14.

What value is stored in the "total" variable after the following code runs?

total = 0

for i in range(1,4):

total = total + i

a)

6

b)

0

c)

5

d)

10

15.

Which of the following best describes how many times the statements in the body of a "while" loop will run?

a)

0, 1 or more times depending on the logical expression of the "while" statement

b)

At least once

c)

A maximum of 10 times no matter what

d)

An infinite number of times until a "continue" statement is reached