Python - Exam 1

0.0(0)
studied byStudied by 18 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/134

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

135 Terms

1
New cards

When the step argument is a negative number, the range function generates a sequence of numbers from the first argument down to the second argument plus 1.

True

2
New cards

What statement regarding precedence of operators is accurate?

The comparison operators (==, !=, <, >, <=, >=) are higher in precedence than the assignment operator (=).

3
New cards

The statements within a while loop can execute one or more times.

False

4
New cards

4 != 4 evaluates to True.

False

5
New cards

In programming, what is a prototype?

It is a rough draft of a program.

6
New cards

What is NOT a Boolean or logical operator used in the Python language?

xor

7
New cards

There are two types of loops—those that repeat an action a predefined number of times (definite iteration) and those that perform the action until the program determines that it needs to stop (indefinite iteration).

True

8
New cards

When using the range function, what effect does the specification of a third argument have?

The third argument specifies a step value to be used in the range.

9
New cards

What comparison operator is used to test whether an expression does NOT equal another expression?

!=

10
New cards

The not operator expects a single operand and returns its logical negation, True, if it's false, and False if it's true.

True

11
New cards

Loop statements allow a computer to make choices.

False

12
New cards

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

The loop body.

13
New cards

Some computer scientists argue that a while True loop with a delayed exit violates the spirit of the while loop.

True

14
New cards

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

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.

15
New cards

In general terms, what does a selection statement do?

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

16
New cards

Simple Boolean expressions consist of the Boolean values True or False, variables bound to those values, function calls that return Boolean values, or comparisons.

True

17
New cards

A condition expresses a hypothesis about the state of its world at that point in time.

True

18
New cards

Assuming that the value of x is 4, and the value of y is 6, what is the value of the following expression? (x - y)**2 > y

False

19
New cards

The use of +=, -=, and *= are all examples of what type of operators?

augmented assignment operators

20
New cards

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

%

21
New cards

What is the minimum number of spaces that should be used to create an indented statement?

four spaces

22
New cards

In Python, = means equals, whereas == means assignment.

False

23
New cards

Although the while loop can be complicated to write correctly, it is possible to simplify its structure and thus improve its readability.

True

24
New cards

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

The variable var1 must be an integer value.

25
New cards

What scenario would it make logical sense to use a multi-way selection statement for?

You need to convert numeric grades to letter grades.

26
New cards

You are running a Python script and suspect that the script has entered an infinite loop. What key combination can you use to halt the loop?

CTRL + c

27
New cards

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

random.randint(1, 6)

28
New cards

What are the two different types of loops that are used within the Python language? (Choose two.)

 

indefinite iteration 

predetermined looping 

definite iteration 

infinite cycling

indefinite iterationdefinite iteration 

29
New cards

For the most part, off-by-one errors result when the programmer incorrectly specifies the lower bound of the loop.

False

30
New cards

Conditional iteration requires that a condition be tested within the loop to determine whether the loop should continue.

True

31
New cards

The assignment symbol can be combined with the arithmetic and concatenation operators to provide augmented assignment operations.

True

32
New cards

"A" < "B" evaluates to False.

False

33
New cards

A while loop can be used for a count-controlled loop.

True

34
New cards

What is a count controlled loop?

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

35
New cards

The or operator returns True if and only if both of its operands are true, and returns False otherwise.

False

36
New cards

Inside of a loop, after a termination condition has been met, what statement can be used to cause an exit from the loop and execute the remainder of the script?

break

37
New cards

The if-else statement is the most common type of selection statement.

True

38
New cards

An off-by-one error is an example of what type of error in programming?

logic error

39
New cards

The simplest form of selection is the if-else statement.

False

40
New cards

The augmented assignment operations have a higher precedence than the standard assignment operation.

False

41
New cards

The not operator has a lower precedence than the and and or operators.

False

42
New cards

The while loop is also called a sentinel-control loop, because its condition is tested at the top of the loop.

False

43
New cards

If A is True, what will the statement "not A" return?

False

44
New cards

The comparison operators are applied after addition but before assignment.

True

45
New cards

In a conditional iteration loop, such as a while loop, what is a sentinel value?

A sentinel value is a special value provided by the user to terminate the loop.

46
New cards

What statement should you use to print the value of total with a precision of 5 digits?

print("The total is %0.5f" % total)

47
New cards

What statement accurately reflects the difference between the quotient operator and the division operator?

The quotient operator produces an integer, while the division operator produces a float.

48
New cards

Real numbers have infinite precision, which means that the digits in the fractional part can continue forever.

True

49
New cards

What is the largest value of an int data type in the Python programming language?

The value is limited only by the memory of the host computer.

50
New cards

What are the two different means by which a floating-point number can be written? (Choose two.)

 

  • scientific notation

  • decimal notation 

  • line notation 

  • octal notation

scientific notation & decimal notation 

51
New cards

What special character does the '\b' escape sequence generate?

It produces a backspace special character, which performs the same function as the backspace key.

52
New cards

The + operator allows you to build a string by repeating another string a given number of times.

False

53
New cards

In the maintenance phase of the waterfall model, the parts of a program are brought together into a smoothly functioning whole, usually not an easy task.

False

54
New cards

What is the total number of distinct values in the ASCII set?

256

55
New cards

What effect does the following print statement have? print("Hello" * 5)

The print statement will produce "HelloHelloHelloHelloHello".

56
New cards

Testing is a deliberate process that requires some planning and discipline on the programmer's part.

True

57
New cards

Python is a loosely typed programming language.

False

58
New cards

A variable associates a name with a value, making it easy to remember and use the value later in a program.

True

59
New cards

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

1ending

60
New cards

Variables receive their initial values and can be reset to new values with an assignment statement.

True

61
New cards

When the Python interpreter evaluates a literal, the value it returns is simply that literal.

True

62
New cards

In Python, % is the exponentiation operator.

False

63
New cards

In general, a variable name must begin with either a letter or an underscore (_).

True

64
New cards

Expressions provide an easy way to perform operations on data values to produce other data values.

True

65
New cards

The design phase of the waterfall model is also called the coding phase.

False

66
New cards

Exponentiation and assignment operations are left associative.

False

67
New cards

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

By removing the fractional value of the number.

68
New cards

1,500 is a valid integer literal in Python.

False

69
New cards

string is an example of a data type in Python.

False

70
New cards

Text processing is by far the least common application of computing.

False

71
New cards

In Python, \b is a escape sequence that represents a horizontal tab.

False

72
New cards

A semantic error is detected when the action that an expression describes cannot be carried out, even though that expression is syntactically correct.

True

73
New cards

The modulus operator has the highest precedence and is evaluated first.

False

74
New cards

In Python, what data type is used to represent real numbers between -10^308 and 10^308 with 16 digits of precision?

float

75
New cards

What statement accurately describes the analysis phase of the waterfall model?

In this phase, the programmers determine what the program will do.

76
New cards

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?

from math import cos, sin

77
New cards

Modern software development is usually incremental and iterative.

True

78
New cards

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

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

79
New cards

The cost of developing software is spread equally over the phases.

False

80
New cards

Which of the following functions and expressions will convert the ASCII character "Z" to its numeric equivalent ASCII code?

ord('Z')

81
New cards

Computer scientists refer to the process of planning and organizing a program as software development.

True

82
New cards

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

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

83
New cards

In Python, what does the "%" operator do in the expression 6 % 4?

It returns a remainder or modulus.

84
New cards

Functions that are always available in Python come from what module?

__builtin__

85
New cards

Programs rarely work as hoped the first time they are run.

True

86
New cards

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?

The variable is a symbolic constant.

87
New cards

In the waterfall development model, what is the most expensive part of software development?

The maintenance phase.

88
New cards

Which of the following literals would be considered a float type in Python?

3.14

89
New cards

What print statement will output a single '\' character?

print(‘\\’)

90
New cards

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?

abstraction

91
New cards

In evaluating the precedence rules used by Python, what statement is accurate?

Exponentiation has the highest precedence.

92
New cards

What function can you call inside of IDLE to show the resources of the math module, once it has been imported?

dir(math)

93
New cards

What statement accurately describes what a semantic error is?

A semantic error occurs when an expression is syntactically correct, but the expression cannot be carried out.

94
New cards

Ancient mathematicians developed the first algorithms.

True

95
New cards

What technology replaced the vacuum tube as the mechanism for implementing electronic switches in computer hardware?

transistor

96
New cards

In a computer, what component is known as the "processor"?

CPU

97
New cards

A program stored in computer memory must be represented in binary digits, which is also known as ASCII code.

False

98
New cards

In the early 1940s, computer scientists realized that a symbolic notation could be used instead of machine code, and the first assembly languages appeared.

False

99
New cards

What language was designed based on a theory of recursive functions and is considered to be an ideal language for solving difficult or complex problems?

LISP

100
New cards

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

translator