AIST 2110 Study Guide: Quizzes 2 to 9

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Get a hint
Hint

What is the function of the secondary memory(like a hard drive or SSD) in a computer?

a. Store information for the long term, even beyond a power cycle

b. Retrieve web pages over the Internet

c. Take input from the user

d. Execute all of the computation and logic of the program

Get a hint
Hint

a. Store information for the long term, even beyond a power cycle

Get a hint
Hint

What is a Python program?

a. A piece of hardware that retrieves information from the Internet.

b. A tool used to manually search through printed documents.

c. A machine that stores data for future use.

d. A sequence of Python statements crafted to solve a problem or

perform a task.

Get a hint
Hint

d. A sequence of Python statements crafted to solve a problem or perform a task

Card Sorting

1/81

Anonymous user
Anonymous user
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.

82 Terms

1
New cards

What is the function of the secondary memory(like a hard drive or SSD) in a computer?

a. Store information for the long term, even beyond a power cycle

b. Retrieve web pages over the Internet

c. Take input from the user

d. Execute all of the computation and logic of the program

a. Store information for the long term, even beyond a power cycle

2
New cards

What is a Python program?

a. A piece of hardware that retrieves information from the Internet.

b. A tool used to manually search through printed documents.

c. A machine that stores data for future use.

d. A sequence of Python statements crafted to solve a problem or

perform a task.

d. A sequence of Python statements crafted to solve a problem or perform a task

3
New cards

What is the difference between a compiler and an interpreter?

a. A compiler and an interpreter are both used to manage user input and

output in the program.

b. A compiler runs a program line by line, while an interpreter translates

the entire program into machine language at once.

c. A compiler is used to store data, while an interpreter retrieves web

pages from the Internet.

d. A compiler translates the entire program into machine language before execution, while an interpreter runs the program line by line.

d. A compiler translates the entire program into machine language before execution, while an interpreter runs the program line by line

4
New cards

Which of the following contains "machine code"?

a. Python source file

b. The Python interpreter

c. The keyboard

d. A word processing document

b. The Python interpreter

5
New cards

Which of the following demonstrates a semantic error in the sentence?

a. Where did the ribbon go?

b. This Open. Verbed --? Outside ... grapes!

c. Wishes hop over the sad emotion.

c. Wishes hop over the sad emotion.

6
New cards

Python comments are notes or explanations that you can write within your code to help you and others understand what the code is doing.

True

False

True

7
New cards

When a program is executed...

a. each line of the program is executed one at a time.

b. the program stops because it has been "killed."

c. each line of the program is executed all at once.

a. each line of the program is executed one at a time

8
New cards

What will the following program print out:

x = 43

x = x - 1

print(x)

a. Error because x = x + 1 is not possible mathematically

b. 42

c. x+1

d. 43

b. 42

9
New cards

What are libraries in Python?

a. Special Python syntax for defining new variables

b. Software for organizing and cataloging digital files

c. Collections of physical books about programming

d. Pre-written code collections that provide useful tools and functions

Pre-written code collections that provide useful tools and functions

10
New cards

What is '98.6' in print(98.6)?

a. An iteration / loop statement

b. A constant

c. A conditional statement

d. A variable

b. A constant

11
New cards

Comment in Python

a. # This is a test

b. // This is a test

c. / This is a test /

d. * This is a test

a. # This is a test

12
New cards

What does the following code print out?

print("123" + "abc")

a. This is syntax error because you cannot add strings

b. 123abc

c. 123+abc

d. 1a2b3c

b. 123abc

13
New cards

Which of the following is the "most mnemonic" variable name

a. hours

b. x

c. x1q3z9ocd

d. variable_173

a. hours

14
New cards

Assume the variable x has been initialized to an integer value (e.g., x = 3).

What does the following statement do?

a. Produce the value "false" because "x" can never equal "x+2"

b. This would fail as it is a syntax error

c. Retrieve the current value for x, add two to it and put the sum back into x

d. Create a function called "x" and put the value 2 in the function

c. Retrieve the current value for x, add two to it, and put the sum back into x

15
New cards

What is the value of the following expression

42 % 10

Hint - the "%" is the remainder operator

a. 420

b. 1042

c. 10

d. 2

d. 2

16
New cards

Type of the literal value "False"

a. String

b. Boolean

c. Float

d. Int

a. String

17
New cards

The result of the code

print(1 < 2 and 4 > 5)

is:

a. 1

b. 1<2 and 4>5

c. True

d. False

d. False

18
New cards

Is the following code reading, writing, or both for the variable x?

y = x + z

a. Write

b. None

c. Read and Write

d. Read

d. Read

19
New cards

Which of the following statements best explains how programs execute

lines of code?

a. The lines are executed from top to bottom in order.

b. All of the lines are executed at the same time.

c. The lines are executed from right to left.

d. The lines are executed in random order.

a. The lines are executed from top to bottom in order

20
New cards

In the following code, where is the print statement relative to

the if statement?

if conditional:

print("The conditional was true.")

a. The print is before the body of the if statement

b. The print is inside the body of the if statement

c. The print is after the body of the if statement

b. The print is inside the body of the if statement

21
New cards

What is true about the following code segment:

if x == 5 :

print('Is 5')

print('Is Still 5')

print('Third 5')

a. The string 'Is 5' will always print out regardless of the value for x.

b. Depending on the value of x, either all three of the print statements will execute or none of the statements will execute

c. Only two of the three print statements will print out if the value of x is less than zero.

d. The string 'Is 5' will never print out regardless of the value for x.

b. Depending on the value of x, either all three print statements will execute or none will

22
New cards

What do we do to a Python statement that is immediately after an if

statement to indicate that the statement is to be executed only when the if

statement is true?

a. Begin the statement with a curly brace {

b. Underline all of the conditional code

c. Indent the line below the if statement

d. Start the statement with a "#" character

c. Indent the line below the if statement

23
New cards

In the following code, how many branches are there?

if conditional:

print(5)

else:

print(2)

a. 1

b. 2

c. 0

b. 2

24
New cards

Which of the following is the correct way to write a conditional statement

that prints "Hello" if the variable y is equal to 10?

a. if (y == 10): print('Hello')

b. if y = 10: print('Hello')

c. if y == 10 print('Hello')

d. if y == 10: print('Hello')

a. if y == 10: print("Hello")

25
New cards

When you have multiple lines in an if block, how do you indicate the end of

the if block?

a. You use a curly brace { after the last line of the if block

b. You omit the semicolon ; on the last line of the if block

c. You de-indent the next line past the if block to the same level of indent as the original if statement

d. You capitalize the first letter of the line following the end of the if block

c. You de-indent the next line past the if block to the same level of indent as the original if statement

26
New cards

What does the following code print?

x = 8

if x >= 8:

print('Equals or Greater than 8')

if x != 5:

print('Not equal to 5')

a. No output

b. Not equal to 5

c. Equals or Greater than 8, Not equal to 5

d. Equals or Greater than 8

c. Equals or Greater than 8, Not equal to 5

27
New cards

VWhat is the value of number_of_users after this program executes?

if False:

number_of_users = 5

print(number_of_users)

a. None, because that is the default value for all variables

b. No Value, as an error occurs since the variable was not defined before it was printed

c. 5, because of the assignment on line 2

b. No Value, as an error occurs since the variable was not defined before it was printed

28
New cards

What is the value of total after this program executes?

total = 5

if total > 3:

total = total + 1

else:

total = total - 1

print(total)

a. 4

b. 6

c. 3

d. 5

b. 6

29
New cards

Which of the following statements about comparison operators is true?

a. Comparison operators change the value of variables.

b. Comparison operators are used to compare two values and return a boolean.

c. Comparison operators always return a string value.

d. Comparison operators only work with integers.

b. Comparison operators are used to compare two values and return a boolean.

30
New cards

According to the following error message, what type of error occurred?

Traceback (most recent call last):

File "my_code.py", line 32, in 45 + "NameError"

TypeError: unsupported operand type(s) for +: 'int' and 'str'"

a. TypeError

b. We cannot tell the type of error from the information provided

c. NameError

d. SyntaxError

a. TypeError

31
New cards

When your program has an error, the first thing you should do is:

a. Ask for help

b. Read the error message and consider its meaning

c. Start debugging your program by changing the code

d. Cry

b. Read the error message and consider its meaning

32
New cards

Python syntax rules prohibit a nested if block from having a corresponding

elif block or else block.

a. True

b. False

b. False

33
New cards

Trace the code below. What is the final value of the salary variable?

salary = 1000

if salary > 100:

taxes = .5

else:

taxes = .1

salary = taxes * salary

if salary > 100:

if salary < 500:

taxes = 0

salary = taxes * salary

a. 0.0

b. 500.0

c. 1000

d. 250.0

d. 250

34
New cards

For the following code:

astr = 'Hello Bob'

istr = 0

try:

istr = int(astr)

except:

istr = -1

What will the value be for istr after this code executes?

a. The istr variable will not have a value

b. It will be the 'Not a number' value (i.e. NaN)

c. -1

d. 0

c. -1

35
New cards

In the following code (numbers added) - which will be the last line to execute successfully?

(1) astr = 'Hello Bob'

(2) istr = int(astr)

(3) print('First', istr)

(4) astr = '123'

(5) istr = int(astr)

(6) print('Second', istr)

a. 1

b. 3

c. 6

d. 5

a. 1

36
New cards

What will the following code print out?

x = 0

if x < 2 :

print('Small')

elif x < 10 :

print('Medium')

else :

print('LARGE')

print('All done')

a. Small

All done

b. Medium

All done

c. Small

Medium

LARGE

All done

d. Small

a. Small

All done

37
New cards

For the following code

if x < 2 :

print('Below 2')

elif x >= 2 :

print('Two or more')

else :

print('Something else')

What value of 'x' will cause 'Something else' to print out?

a. x = 2.0

b. x = -2

c. x = 2

d. This code will never print 'Something else' regardless of the value for 'x'

d. This code will never print 'Something else' regardless of the value for 'x'

38
New cards

Using an "early exit strategy" will always be preferred to using nested

conditionals for input validation.

a. True

b. False

b. False

39
New cards

If my_num is a variable containing a float value, which of the following will

print it with exactly 3 decimal places, including any trailing 0's?

Done

a. round_num = round(my_num, 3)

print(round_num)

b. print(round(my_num, 3))

c. print("{my_num:.3f}")

d. print(f"{my_num:.3f}")

d. print(f"{my_num:.3f}")

40
New cards

In Python what is the input() feature best described as?

a. A module

b. A built-in function

c. A conditional statement

d. A user-defined function

b. A built-in function

41
New cards

The function double below returns the argument multiplied by 2. What

value will the variable x hold after the line is executed?

x = double(2) + double(3)

a. 10

b. 5

c. 6

a. 10

42
New cards

Like mathematical functions, all programming functions must return a

value.

a. True

b. False

b. False

43
New cards

Which of the following is not a good reason why programmers modularize their code?

a. It allows useful bits of code to be easily reused.

b. It makes code easier to understand and maintain.

c. It allows you to organize code logically so you can easily find and use it later.

d. It allows code blocks to snap together like legos.

d. It allows code blocks to snap together like legos.

44
New cards

Which two built-in functions are useful for understanding how to use a

function or a module when running python interactively?

a. help() and dir()

b. print() and input()

c. eval() and exec()

d. type() and len()

a. help() and dir()

45
New cards

All functions must be called with at least one argument.

a. True

b. False

b. False

46
New cards

Though often used interchangeably, arguments are the values passed along

with a function call, while parameters are the named variables in the

function definition that a function uses to access the argument values.

a. True

b. False

a. True

47
New cards

What will be the input of the following code:

max = max(5,4)

max2 = max(10,3,4,7)

print(f"{max} and {max2}")

a. 5 and 10

b. 5, 4 and 10,3,4,7

c. 4 and 3

d. None. The program will generate an error.

d. None. The program will generate an error.

48
New cards

Which of these statements is most accurate?

a. A Package contains modules, which in turn can provide variables after being imported.

b. A module can contain values, which in turn can provide packages after being imported.

c. A Package contains variables, which in turn can provide modules after being imported.

a. A Package contains modules, which in turn can provide variables after being imported.

49
New cards

Select the following that will allow a script to access the cos function and e constant stored in the math module (select all valid answers).

a. import math.cos, math.e

b. import cos, e from math

c. import math(cos, e)

d. import math

e. from math import cos, e

d. import math

e. from math import cos, e

50
New cards

What will the following Python program print out?

def greet(lang):

if lang == 'es':

return 'Hola'

elif lang == 'fr':

return 'Bonjour'

else:

return 'Hello'

print(greet('fr'),'Michael')

a. Bonjour Michael

b. def Hola Bonjour Hello Michael

c. Hola Michael

d. Hola Bonjour Hello Michael

a. Bonjour Michael

51
New cards

Of the following, which is the best reason to write your own functions?

a. Avoiding writing the same non-trivial code more than once in your program

b. To avoid having more than 10 lines of sequential code without an indent or de-indent

c. Following the rule that whenever a program is more than 10 lines you must use a function

d. Following the rule that no function can have more than 10 statements in it

a. Avoiding writing the same non-trivial code more than once in your program

52
New cards

What is the difference between a "fruitful" function and a "void" function in Python?

a. A void function takes more than one argument, while a fruitful function takes only one.

b. A fruitful function returns a value, while a void function does not.

c. A fruitful function takes arguments, while a void function does not.

d. A void function is used for string operations, while a fruitful function is used for numeric operations.

b. A fruitful function returns a value, while a void function does not.

53
New cards

What will the following Python code print out?

def func(x) :

print(x)

func(10)

func(20)

a. 10 20

b. x 20

c. x 10 x 20

d. func func

a. 10 20

54
New cards

Which line of the following Python program will never execute?

def stuff():

print('Hello')

return

print('World')

stuff()

a. def stuff():

b. return

c. print ('World')

d. stuff()

e. print('Hello')

c. print ('World')

55
New cards

Which of the following is true about defining a function in Python?

a. A function cannot call another function within its body.

b. A function definition must include at least one parameter.

c. A function is defined using the def keyword followed by the function name and parentheses.

d. A function must always call return.

c. A function is defined using the def keyword followed by the function name and parentheses.

56
New cards

In what order will the following lines of Python code be executed?

def f(x):

x = x + 1

return x

val = 0

y = f(val)

print(y)

a. 1,2,3,4,5,1,2,3,5,6

b. 4,5,2,3,5,6

c. 1,4,5,6

d. 1,2,3,4,5,6

b. 4,5,2,3,5,6

57
New cards

What is the best way to access the result of one function inside of another function in Python?

a. By ensuring that the returned value of one function is passed as an argument to the other function.

b. By placing both functions inside the same file without any return statements.

c. By directly accessing variables from one function inside another function.

d. By using global variables defined outside both functions.

a. By ensuring that the returned value of one function is passed as an argument to the other function.

58
New cards

What kind and how many different variable scopes are there in this

program?

def make_message(value):

return "The result is" + str(value)

def modify_number(a_number):

return a_number * 5 + 3

start = 10

print(make_message(modify_number(start)))

a. 3 local/function

b. 1 global/module and 4 local/function

c. 2 global/module and 4 local/function

d. 1 global/module 2 local/function

d. 1 global/module 2 local/function

59
New cards

When a function is called inside another function, how does Python

manage the variables and function calls?

a. The called function must return all of its variables to the calling function when it finishes.

b. All variables from both functions are combined into a single scope.

c. The called function inherits the variables from the calling function.

d. Each function call gets its own separate scope, even if the variables have the same name.

d. Each function call gets its own separate scope, even if the variables have the same name.

60
New cards

What will the following Python code print out?

friends = [ 'Joseph', 'Glenn', 'Sally' ]

friends.sort()

print(friends[0])

a. Sally

b. Glenn

c. Joseph

d. friends

b. Glenn

61
New cards

Which of the following slicing operations will produce the list [12, 3]?

t = [9, 41, 12, 3, 74, 15]

a. t[12:3]

b. t[:]

c. t[1:3]

d. t[2:4]

e. t[2:2]

d. t[2:4]

62
New cards

Which of the following statements about lists in Python is true?

a. Lists in Python are immutable.

b. Lists cannot hold elements of different data types.

c. Lists can be indexed and are mutable.

d. Lists do not maintain the order of elements.

c. Lists can be indexed and are mutable.

63
New cards

What list method adds a new item to the end of an existing list?

a. pop()

b. push()

c. add()

d. append()

e. forward()

d. append()

64
New cards

Which function is used to determine the number of elements in a list in

Python?

a. len()

b. count()

c. size()

d. length()

a. len()

65
New cards

Which of the following is NOT a valid way to create a list in Python?

a. my_list = []

b. my_list = list()

c. my_list = { 1, 2, 3 }

d. my_list = [ 1, 2, 3 ]

c. my_list = { 1, 2, 3 }

66
New cards

Given the following code:

words = ["apple", "bat", "crab", "domino", "early"]

Which of the following expressions will produce the value True?

a. "domino" in words

b. "b" in words

c. ["apple", "bat"] in words

a. "domino" in words

67
New cards

What will be the output of the following code?

numbers = [2, 4, 6, 8, 10]

print(numbers[:3])

a. [2, 4, 6, 8]

b. [4, 6, 8]

c. [2, 4]

d. [2, 4, 6]

d. [2, 4, 6]

68
New cards

Given the following code:

words = "crab apple"

Which of the following expressions will produce the value True? (select all

that apply)

a. "b a" in words

b. "apple" in words

c. "crabapple" in words

d. "ape" in words

a. "b a" in words

b. "apple" in words

69
New cards

Given the following code:

words = "apple bat crab domino early"

Which of the following expressions will create the following list? (select all

that apply)

["apple", "bat", "crab", "domino", "early"]

a. ' '.split(words)

b. words.split(' ')

c. words.split()

d. words.split(',')

b. words.split(' ')

c. words.split()

70
New cards

Infinite loops are always a bad thing, so constructs like while True should

be avoided.

a. True

b. False

b. False

71
New cards

Assuming a loop is executing from within a method, which of the following

will NOT cause the loop to terminate?

a. break

b. continue

c. return

d. exit()

b. continue

72
New cards

Given the following code, which line executes immediately after line 7?

counter = 0

answer = "Keisha"

while counter < 3:

counter += 1

resp = input("Enter the right name: ")

if resp == answer:

break

else:

continue

print("Moving on...")

a. 1

b. 3

c. 6

d. 10

d. 10

73
New cards

Given the following code, which line executes immediately after line 9?

counter = 0

answer = "Keisha"

while counter < 3:

counter += 1

resp = input("Enter the right name: ")

if resp == answer:

break

else:

continue

print("Moving on...")

a. 1

b. 3

c. 6

d. 10

b. 3

74
New cards

Which of the following will increment counter by 1 in Python? (choose all

correct answers)

a. counter += 1

b. counter = counter + 1

c. counter + 1

d. counter++

a. counter += 1

b. counter = counter + 1

75
New cards

The counter for a counter-controlled loop must be incremented by exactly

one each time through the loop. Incrementing by a different value or

decrementing is not supported.

a. True

b. False

b. False

76
New cards

Like an if statement, the condition for a while loop can be any boolean

expression (i.e., anything that evaluates to True or False).

a. True

b. False

a. True

77
New cards

It is possible to have other control structures such as if/elif/else and

additional while loops nested inside of a while loop.

a. True

b. False

a. True

78
New cards

Often used to refer to a variable that keeps track of the number of times a loop has cycled (or possibly the number of cycles remaining)

a. tracker

b. accumulator

c. sentinel

d. counter

e. iteration

d. counter

79
New cards

A general term that describes on cycle through a loop

a. tracker

b. accumulator

c. sentinel

d. counter

e. iteration

e. iteration

80
New cards

Another term for the condition that determines whether or not to (continue to) step into a while loop's code block.

a. tracker

b. accumulator

c. sentinel

d. counter

e. iteration

c. sentinel

81
New cards

As defined in the book, a variable that is initialized outside of a loop, but expanded or increased (by collecting, adding, concatenating, etc.) inside of a loop.

a. tracker

b. accumulator

c. sentinel

d. counter

e. iteration

b. accumulator

82
New cards

as defined in the lectures, a variable that is initialized outside of a loop that is conditionally updated inside of a loop to remember something significant value such as the first, last, largest, or smallest value encountered.

a. tracker

b. accumulator

c. sentinel

d. counter

e. iteration

a. tracker