Python Midterm

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/180

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.

181 Terms

1
New cards

John von Neumann is known for the observation that the number of transistors that fit on a computer chip doubles every year

False

2
New cards

The term hertz can be used to describe a computer's speed.

True

3
New cards

Information in secondary memory is lost if the power is turned off.

False

4
New cards

What components are part of the von Neumann model?

control unit, arithmetic logic unit, memory, input and output

5
New cards

Who developed the Python programming language?

Guido van Rossum

6
New cards

Python is a general-purpose programming language, appropriate for solving problems in many areas of computing.

True

7
New cards

The Python programming language was so named after a snake was discovered in the creator's office.

False

8
New cards

Python 3 is backwards compatible to Python 2.

False

9
New cards

Python embodies elements of which programming paradigm?


Procedural programming

Object-oriented programming

Functional programming

10
New cards

Which of the following is NOT a principle embraced by the Python programming language?

Verbose is better than succinct

11
New cards

Thonny is best described as which of the following?

Integrated Development Environment(IDE)

12
New cards

The output of a Python program run in Thonny appears in the shell window.

True

13
New cards

Thonny displays code using syntax highlighting.

True

14
New cards

Running a program that contains errors will cause the Thonny development environment to terminate.

False

15
New cards

Thonny has a package manager that lets you install and update external Python packages.

True

16
New cards

A Python program must be enclosed in curly braces { } to be executed.

False

17
New cards

Which of the following statements is true??

The print statement is a call to a function.

18
New cards

A Python program must compiled into an executable form before it can be run.

False

19
New cards


What is syntax coloring?

Showing certain elements of program code in different color

20
New cards

What does the term case sensitive mean?

The difference between upper and lowercase letters matter

21
New cards

Why don't we use natural languages (like English) to program a computer?

Natural languages are semantically ambiguous

22
New cards

What is the syntax of a language?

The rule that determine how words and symbols can be combined

23
New cards

In a programming language, a syntactically valid statement has only one meaning.

True

24
New cards

A program that runs without generating a runtime error will produce correct results.

False

25
New cards

Which of the following would cause a syntax error?

Misspelling a keyword

26
New cards

Which of the following would cause a runtime error?

Dividing by zero

27
New cards

Computing the wrong answer is an example of what kind of error?

logic error

28
New cards

Debugging is the process of:

Finding the root cause of an error and fixing it

29
New cards

The code you write is called Python bytecode.

False

30
New cards

To run a Python program, the interpreter combines your code with any library code your program uses.

True

31
New cards

Python bytecode is not associated with any particular type of computer processor.

True

32
New cards

The Python package installer is called pip.

True

33
New cards

A graphical representation of the logic of an algorithm.

flowchart

34
New cards

A step-by-step procedure for solving a problem.

algorithm

35
New cards

The data needed by an algorithm to accomplish its task.

input

36
New cards

The level at which an instruction is expressed.

granularity

37
New cards

A language that humans use to communicate, such as French or English.

natural language

38
New cards

The data produced by an algorithm.

output

39
New cards

A language that is independent of any particular programming language.

pseudocode

40
New cards

What output does the following code produce?

print(‘apple’ , ‘banana’)

apple banana

41
New cards

What output is produced by the following code?

print(15+30)

45

42
New cards

What output does the following code produce?

print('Ready', end=' ')
print('Set', end='')
print('Go')

Ready SetGo

43
New cards

What output is produced by the following code?

print('Jan', 'Feb', 'Mar', sep='-')

Jan-Feb-Mar

44
New cards

What output is produced by the following code?

print('oak', 'elm', 'pine', end='!', sep='#')

oak#elm#pine!

45
New cards

What operator is used to perform string concatenation in Python?

+

46
New cards

What output does the following code produce?

print('Total: ' + 100 + 20)

No output. This line would produce an error. (You cant concatenate a string and an integer)

47
New cards

What issue must be addressed when printing a long character string?

A regular string literal cannot span across multiple lines. (use triple quote)

48
New cards

If a variable called pioneer refers to the string 'Grace Murray Hopper', what is the result of the expression len(pioneer)?

19

49
New cards

If a variable called business refers to the string 'Time Warner', what is the result of the expression business[6]?

‘a’

50
New cards

If a variable called son refers to the string 'Justin', what is the result of the expression son[-3]?

‘t’

51
New cards

You cannot change the contents of Python character string once it has been created.

True

52
New cards

If a variable called jedi refers to the string 'Yoda', what is the result of the expression jedi * 3?

YodaYodaYoda

53
New cards

Python comments begin with a hash mark (#) and extend to the end of the line

True

54
New cards

A comment in a Python program is ignored by the interpreter.

True

55
New cards

A Python comment cannot appear on a line that contains an executable statement.

False

56
New cards

A Python block comment begins with a double slash (//).

False

57
New cards

What is a docstring?

A character string used as a comment in a program.

58
New cards

Python variables that represent integers are NOT object reference variables.

False

59
New cards

In dynamically typed languages, variables are declared to store a specific type of data.

False

60
New cards

Which of the following identifiers follows the convention for naming Python variables?

total_value

61
New cards

Which of the following is NOT a valid Python identifier?

1stPlace

62
New cards

The value of a variable can change throughout a program.

True

63
New cards

Python variables are created using an assignment statement.

True

64
New cards

Suppose the integer variable hours contains a value that represents a number of hours. Which of the following expressions will compute how many 24-hour periods are represented by that value, without worrying about any leftover hours.

hour // 24

65
New cards

If the variable num contains a positive integer, what are the only two possible results of the expression num % 2?

0 and 1

66
New cards

What is the result of the expression 43 % 5?

3

67
New cards

What is the result of the expression 7 // 2?

3

68
New cards

The math module contains a constant that represents the value pi to several digits.

True

69
New cards

The expression x ^ y raises the value x to the power y.

False

70
New cards

If both operands to the remainder operator (%) are positive, a divisor of n will produce a result in the range 1 to n.

False

71
New cards

If either or both operands to the division operator (//) are floating-point values, then the result will be a floating-point value.

True

72
New cards

The value assigned to a variable could be a floating point number.

True

73
New cards

In Python, the assignment statement is also an expression.

False

74
New cards

The value assigned to a variable must be numeric.

False

75
New cards

What value is assigned to the variable num by the following statement if the current value of num is 4?

num = num * 2

8

76
New cards

The assignment operator has higher precedence than the arithmetic operators.

False

77
New cards

The input function will produce an error if the value read is not numeric.

False

78
New cards

The inputint, and float functions are all built-in functions.

True

79
New cards

The input function always returns the read data as a character string.

True

80
New cards

What is text that requests user input called?

prompt

81
New cards

Which of the following does the input function NOT do when it is called?

convert the user input to an integer

82
New cards

What will happen if the variable total has the value 5 when the following code is executed?

if total > 8:
     print('collywobbles')

The word collywobbles is not printed and processing continues

83
New cards

Which value of num will cause the print statement in the following code to be executed?

if num < 15:
    if num + 7 >= 20:
        print('There you go!')

13

84
New cards

3

What output is printed by the following code if it is executed when appetizer is 3 and entree is 12?

if appetizer > 1:
    if entree < 7:
        print('ketchup')
    else:
        print('mustard')
else:
    if appetizer < 0:
        print('mayonnaise')
    else:
        print('relish')

mustard

85
New cards

Which of the following statements is true?

The statements in the body of an if must be indented

86
New cards

Of the options given, what values of the variables heightsize, and widthwould cause the following code to set the variable weight to 100?

if height < size:
    weight = 50
    if width < 20:
        print('short')
else:
    if width > 100:
        weight = 100
    println('tall')

height = 15, size = 10, width = 110

87
New cards

An if statement cannot have both an elif and an else clause.

False

88
New cards

The relational operators all return boolean results.

True

89
New cards

The result of a relational operator can be assigned to a variable.

True

90
New cards

The arithmetic operators have a lower precedence than the relational operators.

False

91
New cards

Which of the following is a relational operator?

<=

92
New cards

Which of the following expressions could be used to determine if a is not less than b?

a>=b

93
New cards

In Python, the relational operators can be used to put character strings in alphabetical order.

True

94
New cards

The less than operator (<) should not be used to compare floating point values.

False

95
New cards

A character string can be used as the condition of an if statement.

True

96
New cards

Strings containing non-alphabetic characters cannot be compared using the relational operators.

False

97
New cards

Which of the following conclusions is NOT true when using relational operators to compare character strings?

‘reset’ come before ‘reserve’

98
New cards

Which of the following conclusions is NOT true when using relational operators to compare character strings?

‘fantastic’ comes before ‘Great’

99
New cards

When using relational operators to compare character strings, 'ZEBRA'comes before 'ALLIGATOR'.

False

100
New cards

When using relational operators to compare character strings, 'Music'comes before 'music'.

True