wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Ch 1-3

Total questions: 25

Worksheet time: 2hrs 16mins

Name
Class
Date
1.

Which of the following is NOT a valid name that can be used for a variable?

a)

floater

b)

total

c)

11great

d)

propertyTax

2.

What program is used by a programmer to convert high-level code into executable code?

a)

translator

b)

run-time system

c)

interpreter

d)

text editor

3.

The while loop is also known as what kind of a loop?

a)

infinite loop (Never ends)

b)

exit-controlled (Happens at least once) loop

c)

entry-controlled (May or May Never Happen) loop

d)

count controlled loop(uses a range of values)

4.

What term describes the process of substituting a simple process for a complex process in a program to make the program easier to understand and maintain?

a)

refactoring

b)

abstraction

c)

inheritance

d)

instantiation

5.

What character is used as the format operator when formatting output?

a)

%

b)

" "

c)

\

d)

$

6.

What kind of programming language is Python?

a)

interpreted

b)

compiled

c)

machine

d)

discovered

7.

You are reviewing the code written by another programmer and encounter a variable whose name is entirely in capital letters. What might you discern from this variable name?

a)

title to program

b)

constant value

c)

a variable

d)

a library

8.

In Python, what does the "%" operator do in the expression 10 % 3?

a)

Raises 10 to the power of 3

b)

turns 10 into 0.10 and then multiplies by 3

c)

returns the whole number answer to a division problem

d)

returns the remainder of a division problem

9.

What is a count controlled loop?

a)

It is a loop that counts iterations until a sentinel value is received.

b)

It is a loop that prints out a count of values for the user.

c)

It is a loop that continues based on a certain time interval.

d)

It is a loop that counts through a range of numbers to control when the loop ends.

10.

What part of the loop comprises the statements to be executed?

a)

header

b)

body

c)

end

d)

trailer

11.

What function call will generate a random number in the range of 1 through 6 using the random module?

a)

random.randnum(1, 6)

b)

random.randint(range(1-6))

c)

random.randint(1, 6)

d)

random.random(1, 6)

12.

What must be done in order to concatenate a string and a float object?

a)

Nothing can be done, as the two data types cannot be converted to a compatible type.

b)

The string object must be converted to a float object via the float() function.

c)

The float object must be converted to an integer object via the int() function.

d)

The float object must be converted to a string object via the str() function.

13.

Given the following statement: "%4d" % var1, which of the following is accurate?

a)

The variable var1 must be an integer value.

b)

The variable var1 must be a string value.

c)

The variable var1 will be in octal format.

d)

The variable var1 will be formatted regardless of type.

14.

In general terms, what does a selection statement do?

a)

It forces a computer to favor one value over another.

b)

It allows a computer to make choices based on test conditions.

c)

It allows a computer to select the values that are most economical.

d)

It allows a computer to selectively execute based on processing cost.

15.

When attempting to produce a correct program, what is the point of developing a test suite?

a)

To provide a small set of inputs as a test to verify that a program will be correct for all inputs.

b)

To modify the running program's variables and verify that the program will still function, even if the code changes.

c)

To test the outputs of a program against known values to verify that the math coprocessor is performing properly.

d)

To test the code syntax for possible errors such as undefined variables.

16.

At what point in the interpretation of a Python program are syntax error messages generated?

a)

After the conversion of the code into byte code.

b)

Before execution of the program, when it is passed through the translator.

c)

During execution of the program by the Python virtual machine.

d)

After user input defined by the program is collected.

17.

How does the int function convert a float to an int?

a)

By rounding to the nearest whole number.

b)

By removing the fractional value of the number.

c)

By rounding up to the closest whole number.

d)

By rounding down to the closest whole number.

18.

When a Python interpreter runs a script, what is the script translated into?

a)

assembly code

b)

byte code

c)

interpolated language code

d)

high level language code

19.

What is a one-way selection statement in the context of Python?

a)

It is a single if statement without a corresponding else statement used to test a condition and run statements, then proceed to the next statement.

b)

It is a single if-else statement block that is used to test a condition and run statements, as well as provide a default path for execution.

c)

It is a switch statement block that is used to direct the flow of data based on a single condition.

d)

It is an if statement that tests no conditions, but provides a block for execution.

20.

You are working on a Python script that relies heavily on the cos and sin functions of the math module. As these are the only functions you require, what should you do to import only these functions, rather than the whole math module?

a)

import cos, sin

b)

import cos, sin from math

c)

import math.cos, math.sin

d)

from math import cos, sin

21.

What is the value of string1 after the following statement is executed?

string1 = "hello"[:3] + "python"[0]

a)

lpython

b)

llo

c)

help

d)

lop

22.

What is the output of the following code? EACH { is a tab -- tab will not format)

sum = 0

for value in range(1,4):

{

if value == 2:

{

sum = sum**2

sum += value

}

}

print(sum)

a)

6

b)

12

c)

8

d)

16

23.

What is the output of the following code? { represents a tabbed section

sum = 0

value = 3

while value <= 5:

{

sum += value

value += 1

}

print(sum)

a)

15

b)

10

c)

12

d)

18

24.

11001100 = ___________ base 10

a)

204

b)

314

c)

8

d)

208

25.

78 = _________________ Base 2

a)

01001110

b)

001101110

c)

00011111

d)

10101011