Scripting exam 1

Ace your homework & exams now with Quizwiz!

15 _____ 3 = 0 a. % b. / c. // d. *

a. %

What should XXX and YYY be so that the final output shows how many negative values are input? n = 0 val = Get next input While val is not 0 If XXX YYY val = Get next input put n to output a. XXX: val < 0, YYY: n = n + 1 b. XXX: val < 0, YYY: n = n + val c. XXX: val > 0, YYY: n = n + 1 d. XXX: val < 0, YYY: val = val + 1

a. XXX: val < 0, YYY: n = n + 1

What is the ending value of x? x = 0 i = 1 while i <= 6: x += i i += 2 a. 4 b. 9 c. 15 d. 21

b. 9

The Python language began development in the late _____'s. a. 1940 b. 1960 c. 1980 d. 2010

c. 1980

15 _____ 3 = 5.0 a. % b. ^ c. / d. //

c. /

A _____ is a word that is part of the Python language and can't be used as a variable name. a. keyword b. special token c. syntax symbol d. stylized word

a. keyword

Which statement reads a user-entered string into variable user_name? a. input = user_name() b. user_name = input() c. input() => user_name d. user_name = "input()"

b. user_name = input()

What is the output? num_list = [ 8, 2, 1, 3, 4, 7, 6 ] for index, value in enumerate(num_list): if index == value: print('*', end='') print(value, end=' ') a. 8 2 1 *3 4 7 6 b. 8 *2 1 3 4 7 6 c. 8 2 1 *3 *4 7 *6 d. *8 *2 *1 *3 *4 *7 *6

c. 8 2 1 *3 *4 7 *6

A _____ can be located in a dictionary and is associated with a value. a. value b. pair c. list d. key

d. key

How many times will the body of the loop execute? my_list = [6, 2, 8, -1, 12, 15, -7] x = Get first my_list value While x is not negative: put "Positive number!" to output x = Get next my_list value Put "Done" to output a. 3 b. 4 c. 5 d. 7

a. 3

A sequence of instructions that solves a problem is called _____. a. an algorithm b. a process c. an allegory d. turtle graphics

a. an algorithm

A _____ is a computer component that stores files and other data. a. disk b. monitor c. keyboard d. processor

a. disk

Which has an error? Assume x = 10 and y = 20. a. if x = y: b. if x < y: c. if x <= y: d. if x != y:

a. if x = y:

Objects like integers and strings that can't be modified are called ____. a. immutable b. mutable c. frozen d. set

a. immutable

Which function converts a string to an integer? a. int() b. integer() c. string_to_int() d. convert(string, int)

a. int()

How many times does the while loop execute for the given input values of -1 4 0 9? user_num = 3 while user_num > 0: # Do something user_num = int(input()) a. 0 b. 1 c. 2 d. 3

b. 1

0s and 1s are known as ___ . a. switches b. bits c. voltage d. electricity

b. bits

Which data type is the correct choice to store the number of wins associated with each basketball team in the NBA? a. float b. string c. tuple d. dict

d. dict

Fill in the blank so that the loop displays all odd numbers from 1 to 100. i = 1 while i <= 100: print(i) i = _____ a. 1 b. i + 1 c. 2 d. i + 2

d. i + 2

A processor is a circuit that executes a list of _____. a. bits b. switches c. memories d. instructions

d. instructions

A(n) _____ is a program that executes a script. a. app b. compiler c. processor d. interpreter

d. interpreter

Which branch structure does a program use to output "Yes" if a variable's value is positive, or "No" otherwise? a. if b. else c. if-else d. if-elseif-else

c. if-else

A computer processor stores numbers using a base of _____. a. 16 b. 10 c. 8 d. 2

d. 2

What is a possible output? rentals = { 'skis' : 20.00, 'boots' : 10.00, 'skates' : 4.00 } for x in rentals: print(x, end=' ') a. skis boots skates b. 20.00 10.00 4.00 c. skis: 20.00 boots: 10.00 skates: 4.00 d. x x x

a. skis boots skates

Which formatting presentation type is used to display the integer 43 as 0X2b (hexadecimal in uppercase)? a. h b. H c. x d. X

d. X

Because Python 2.7 programs cannot be run by the Python 3.0 interpreter, Python 3.0 is not _____. a. open-source b. a scripting language c. standalone d. backwards-compatible

d. backwards-compatible

What is the output? for j in range(2): for k in range(4): if (k == 2): break print('{:d}{:d}'.format(j, k), end=' ') a. 00 01 02 b. 00 01 02 03 c. 00 01 10 11 d. 00 01 02 10 11 12

c. 00 01 10 11

What is the base 2 representation of the decimal number: 35? a. 00000035 b. 00011001 c. 00100011 d. 00011011

c. 00100011

What is the ending value of z? x = 0.3 z = math.pow(math.ceil(x), 2) a. 0.0 b. 0.09 c. 1.0 d. 1.09

c. 1.0

What is the value of 11 // 2? a. 5 b. 6 c. 0 d. -5

a. 5

What conditions have to be true to make the following code display "B"? if color == 'red': if style < 3: print('A') elif style < 5: print('B') else: print('C') elif color == 'blue': print('D') a. color is 'red' and style is 4 b. color is 'red' and style is 5 c. color is 'red' and style is 6 d. color is 'blue' and style is 3

a. color is 'red' and style is 4

Which XXX/YYY combination will create a rectangle of '*' characters, with 5 rows, and each row containing 10 '*' characters? for XXX: for YYY: print('*', end='') print() a. i in range(5) / j in range(10) b. i in range(10) / j in range(5) c. i in range(1, 5) / j in range(1, 10) d. i in range(0, 4, '*'), j in range(0, 9, '*')

a. i in range(5) / j in range(10)

A programmer must write a 500 line program. Which is most likely the best approach? a. Write 1 line, run and debug, write 1 more line, run and debug, repeat b. Write 10-20 lines, run and debug, write 10-20 more lines, run and debug, repeat c. Write 250 lines, run and debug, write 250 lines, run and debug d. Write 500 lines, run and debug

b. Write 10-20 lines, run and debug, write 10-20 more lines, run and debug, repeat

Which expressions for YYY and ZZZ will output "Young" when user_age is less than 20 and "Young but not too young" when user_age is between 10 and 20? age_type = '' if YYY: age_type = age_type + "Young" if ZZZ: age_type = age_type + " but not too young" print(age_type) a. YYY: user_age < 20 ZZZ: user_age < 10 b. YYY: user_age < 20 ZZZ: user_age > 10 c. YYY: user_age > 20 ZZZ: user_age < 10 d. YYY: user_age > 20ZZZ: user_age > 10

b. YYY: user_age < 20 ZZZ: user_age > 10

The Python language is developed by a public community of users, therefore Python is a(n) _____ language. a. buggy b. open-source c. open-space d. beginner

b. open-source

Which statement outputs the text: "I won't quit!"? a. print(I won't quit!) b. print("I won't quit!") c. print('I won't quit!') d. print('I won't quit!', punctuation=True)

b. print("I won't quit!")

Which instruction displays variables or expression values? a. put() b. print() c. output() d. display()

b. print()

Which print statement displays the value of a variable called argv in a module called sys? a. print(argv in sys) b. print(sys.argv) c. print(sys_argv) d. print(module sys var argv)

b. print(sys.argv)

Which range() function call generates every even number between 20 and 30 (including both 20 and 30)? a. range(20, 30, 2) b. range(20, 31, 2) c. range(30, 20, 2) d. range(20, 22, 24)

b. range(20, 31, 2)

Which statement has a syntax error? Assume variables x, y, z, and age have already been defined. a. y = y b. x + y = z c. age = '32' d. print('Name, age')

b. x + y = z

What is the output? num = 10; while num <= 15: print(num, end=' ') if num == 12: break num += 1 a. 10 b. 10 11 c. 10 11 12 d. 10 11 12 13 14 15

c. 10 11 12

Which of the following loops is best implemented with a while loop? a. Checking to see if a list of integers contains the value 12. b. Counting how many keys in a dictionary start with the letter 'A'. c. Asking the user to enter positive integers, exiting by entering -1. d. Looping through the characters in a string, and displaying 'yes' if it contains a vowel.

c. Asking the user to enter positive integers, exiting by entering -1.

Which statement makes the code in the math module available? a. use math b. allow math c. import math d. include math

c. import math

For the given pseudocode, which XXX and YYY will output the sum of the input integers (stopping when -1 is input)? Choices are in the form XXX / YYY. val = Get next input XXX While val is not -1 YYY val = Get next input Put sum to output a. sum = val / sum = val b. sum = val / sum = sum + val c. sum = 0 / sum = sum + val d. sum = 0 / sum = val

c. sum = 0 / sum = sum + val

Which statement assigns the string variable airport_code with the value JFK? a. airport_code = 'JFK' b. airport_code = JFK c. 'JFK' = airport_code d. JFK = 'airport_code'

a. airport_code = 'JFK'

Dictionaries are containers used to describe a(n) _____ relationship. a. associative b. one-to-one c. recursive d. isolated

a. associative

Which method call returns the number of elements in my_list? a. len(my_list) b. size(my_list) c. my_list.count() d. my_list.size()

a. len(my_list)

Which operator is evaluated last in an expression? a. or b. and c. == d. +

a. or

Which print statement displays: 'Tokyo had 9.273000 million people in 2015'? a. print('{:s} had {:f} million people in {:d}'.format('Tokyo', 9.273, 2015)) b. print('{:s} had {:f} million people in {:d}', ('Tokyo', 9.273, 2015)) c. print('{:s} had {:d} people in {:d}.format('Tokyo', 9273000, 2015)) d. print({:s} + ' had ' + {:d} + ' million people in ' + {:d}, ('Tokyo', 9.273, 2015))

a. print('{:s} had {:f} million people in {:d}'.format('Tokyo', 9.273, 2015))

Which choice fills in the blank so that the output prints one line for each item in sports_list, as in: 1. Hockey? sports_list = [ 'Hockey', 'Football', 'Cricket' ] for i in _____: print('{:d}. {:s}'.format(i+1, sports_list[i])) a. range(len(sports_list)) b. range(len(sports_list-1) c. range(1, len(sports_list)) d. range(1, len(sports_list)-1)

a. range(len(sports_list))

Fill in the blank so that the output is a count of how many negative values are in temperatures? temperatures = [-2, 8, 4, -7, 18, 3, -1] count = 0 for t in temperatures: if _____: count = count + 1 print("Total negative temperatures:", count) a. t < 0 b. temperatures < 0 c. temperatures[t] < 0 d. t[temperatures] < 0

a. t < 0

Which symbol represents the multiplication operation in programming? a. . b. * c. x d. ( )

b. *

What sequence is generated by range(4)? a. 4 b. 0 1 2 3 c. 1 2 3 4 d. 0 1 2 3 4

b. 0 1 2 3

What is the base 2 representation of the decimal number: 12? a. 00000110 b. 00001100 c. 00001101 d. 11010000

b. 00001100

What is the base 10 representation of the binary number: 00101110? a. 23 b. 46 c. 92 d. 1218

b. 46

What is the base 10 representation of the binary number: 00001001? a. 5 b. 9 c. 17 d. 1001

b. 9

A child is required to use a booster seat in a car until the child is 9 years old, unless the child reaches the height of 59 inches before age 9. Which expression can be used to decide if a child requires a car seat or not? a. if age < 9 or height < 59: b. if age >= 9 or height >= 59: c. if age >= 9 and height >= 59: d. if age <= 9 and height <=59:

b. if age >= 9 or height >= 59:

What does print("one\\two\\\\three") display? a. one\\two\\\three b. one\two\\three c. one twothree d. one\\\\two\\\\\\\\three

b. one\two\\three

Which expression using parentheses is equivalent to the following expression: x - y * -z / 3 a. (x - y) * ((-z) / 3)) b. x - ((y * (-z)) / 3) c. x - (y * ((-z) / 3)) d. (x - (y * (-z))) / 3

b. x - ((y * (-z)) / 3)

Excess indentation must be removed from which lines to make the code correct? 1. print('start') 2. if x > 10: 3. print('large') 4. else: 5. print('small') 6. print('done') a. 1, 6 b. 1, 2, 3 c. 2, 3, 4 d. 2, 4, 5

c. 2, 3, 4

A company wants to send a reminder email to users who have not logged in for more than 10 days, but less than 20 days. Which expression can be used to decide if a user should get an email or not? a. if days_since_login > 10: b. if days_since_login > 10 or days_since_login < 20: c. if days_since_login > 10 and days_since_login < 20: d. if days_since_login > 10 and not days_since_login < 20:

c. if days_since_login > 10 and days_since_login < 20:

Which expression replaces ZZZ to make the loop ask for names until 'quit' is entered? name = input("What is your name ('quit' to exit)? ") while ZZZ: print('Hello, ', name) name = input("What is your name ('quit' to exit)? ") a. name == 'quit' b. name is not 'quit' c. name != 'quit' d. 'quit' is False

c. name != 'quit'

Which statement is equivalent to the following? if x == 1: t = 'minute' else: t = 'minutes' a. t = 'minutes' if x == 1 else 'minute' b. t = 'minute' if x != 1 else 'minutes' c. t = 'minute' if x == 1 else 'minutes' d. t = 'minute' + ('s' if x == 1 else '')

c. t = 'minute' if x == 1 else 'minutes'

In an instruction like: z = x + y, the symbols x, y, and z are examples of _____. a. output b. visibles c. variables d. instructions

c. variables

Which operator is evaluated first: x + y < y - z * 2 ? a. + b. < c. - d. *

d. *

What is the output? for i in range(11): if i == 6: continue else: print(i, end=' ') a. 0 1 2 3 4 5 b. 0 1 2 3 4 5 6 c. 0 1 2 3 4 5 7 8 9 d. 0 1 2 3 4 5 7 8 9 10

d. 0 1 2 3 4 5 7 8 9 10

What is the output? num_list = [ 3, 8, 5, 15, 12, 32, 45 ] for index, value in enumerate(num_list): if index > 0: if value < num_list[index-1]: print('*', end='') print(value, end=' ') a. 3 8 5 15 12 32 45 b. *3 8 5 15 12 32 45 c. *3 *8 5 *15 12 *32 *45 d. 3 8 *5 15 *12 32 45

d. 3 8 *5 15 *12 32 45

How many times will the print statement execute? for i in range(10): for j in range(3): print('{:d}. {:d}'.format(i, j)) a. 3 b. 10 c. 13 d. 30

d. 30

What initial value of x will cause an infinite loop? x = int(input()) while x != 0: x = x - 2 print(x) a. 0 b. 2 c. 4 d. 7

d. 7

Which runtime error type occurs when trying to convert 'abc' to an integer? a. TypeError b. LogicError c. NameError d. ValueError

d. ValueError

What is the name of the data type used for floating point numbers? a. float b. decimal c. non_integer d. floating_point

a. float

What is output when the following code is executed? score = 65 group = '' if score <= 60: group = group + 'A' if score <= 70: group = group + 'B' if score <= 80: group = group + 'C' else: group = group + 'D' print(group) a. C b. D c. AB d. BC

d. BC

Which program can be used to create a Python file that can be used directly by the interpreter? a. IDLE editor b. Word c. Gmail d. Excel

a. IDLE editor

In Python, which of the following literals is shown in valid scientific notation? a. 3.0004e-12 b. 17.012s14 c. 0.003x10^-5 d. e12f3.04

a. 3.0004e-12

What is an IDE used for? a. Program development, including writing the source code. b. Publishing an app in an app store. c. Searching for open-source applications that perform a specific task. d. Deciding which programming language is best suited for a specific application.

a. Program development, including writing the source code.

Which of the following statements about my_list is false? my_list = ['JFK', 'LAX', 'MIA'] a. The element at index 1 is 'JFK' b. The list has a length of 3 c. The list elements are all strings d. The index of the last item in the list is 2

a. The element at index 1 is 'JFK'

62) What is the value of the __name__ built-in variable in a module that is executed as a script by the programmer? a. __main__ b. __direct__ c. __module__ d. __executed__

a. __main__

An item passed to a function is a(n) _____ . a. argument b. instruction c. call d. module

a. argument

What is a common word for the textual representation of a program? a. code b. prompt c. interpreter d. expression

a. code

Which type of error does not cause the program to crash? a. logic error b. value error c. indentation error d. assignment error

a. logic error

41) Which of the following identifiers is valid? a. max_age b. 32area c. transfer$ d. True

a. max_age

Which of the following assignment statements creates a list with 4 integer elements? a. my_list = [7, 2, -8, 16] b. my_list = [4] c. my_list = ['1', '2', '3', '4'] d. my_list = integer(4)

a. my_list = [7, 2, -8, 16]

Which of the following statements assigns a new variable, my_set, with a set that contains three elements? a. my_set = set([1, 2, 3]) b. my_set = set(3) c. my_set = [1, 2, 3].to_set() d. my_set = { [1, 2, 3] }

a. my_set = set([1, 2, 3])

Basic instruction types are input, process, and _____. a. output b. memory c. calculation d. assignment

a. output

Which print statement would display the letter 'A'? (Note that the code point for the letter 'A' is 65.) a. print(chr(65)) b. print(ord(65)) c. print(unicode(65)) d. print(code_point(65))

a. print(chr(65))

In the statement: age = input('Enter your age: ') , the string 'Enter your age: ' is called a(n) _____. a. prompt b. prefix c. variable d. assignment

a. prompt

Dividing by zero is an example of which type of error? a. runtime b. syntax c. logic d. infinity

a. runtime

What values are in result_set after the following code is run? my_set = {1, 2, 3, 4, 5, 6} other_set = {2, 4, 6} result_set = other_set.difference(my_set) a. { } b. {1, 3, 5} c. {2, 4, 6} d. {1, 2, 3, 4, 5, 6}

a. { }

Consider the following program: t = 15 t = t * 2 t = t + 1 t = t - 4 put t What does the program produce as output? a. 11 b. 27 c. 12 d. 15

b. 27

Which of the following expressions causes an implicit conversion between types? Assume variable x is an integer, t is a float, and name is a string. a. "Hello, " + str(name) b. 7.5 + (x / 2) c. print(str(t)) d. x + 2 * x

b. 7.5 + (x / 2)

Which type of program converts a high-level language program into machine instructions? a. App b. Compiler c. Processor d. Assembler

b. Compiler

Which statement correctly explains a difference between lists and tuples? a. The built-in function len() works with lists but not with tuples. b. List items can be changed, while tuple items can't be changed. c. List items can be of any type, while tuple types can only be numbers. d. List items use [ ] operators to access items by index, while tuples use ( ) operators to access items by index.

b. List items can be changed, while tuple items can't be changed.

Which of the following statements has a syntax error? Assume age and years are variables that have already been defined. a. age = years - 2 b. age + 2 = years c. age = 17 - 2 d. age = -15

b. age + 2 = years

A language is called _____ when upper case letters in identifiers are considered different from lower case letters. a. unambiguous b. case sensitive c. case strict d. camel case

b. case sensitive

Which statement changes the value associated with key "Lemon" to 0.75 in the dictionary fruits_dict? a. fruits_dict[0.75] = "Lemon" b. fruits_dict["Lemon"] = 0.75 c. fruits_dict[Lemon] = 0.75 d. dict("Lemon") = fruits_dict[0.75]

b. fruits_dict["Lemon"] = 0.75

Which statement removes the last element of my_list a. my_list.pop(len(my_list) b. my_list.pop(len(my_list)-1) c. my_list.remove(len(my_list)) d. my_list.remove(len(my_list)-1)

b. my_list.pop(len(my_list)-1)

Assigning a value to a floating point variable that is too large for the computer to represent is a condition called _____ . a. bit error b. overflow c. overcapacity d. system error

b. overflow

Which pair shows the correct classification of the given data type? a. tuple, mutable sequence type b. string, immutable sequence type c. int, numeric floating-point type d. dict, immutable sequence type

b. string, immutable sequence type

According to Python's precedence rules, which of the following operators has the highest precedence? a. subtraction - b. unary - c. * d. +

b. unary -

What is displayed when the following code is executed? empty_string = '' print(len(empty_string)) a. "empty" b. 1 c. 0 d. "0"

c. 0

What is the value of y after the following code is executed? Note that the question asks for y, not x. x = 10 y = x + 2 x = 12 a. 8 b. 10 c. 12 d. 14

c. 12

What is the value of: 1 + int(3.5) / 2? a. 2 b. 2.25 c. 2.5 d. 3

c. 2.5

Which statement is true regarding the pop() method for sets? a. pop() removes the first item added to the set. b. pop() removes the last item added to the set. c. pop() removes a random item in the set. d. pop() returns but does not remove a random item in the set.

c. pop() removes a random item in the set.

The variable emails_dict is assigned with a dictionary that associates student ids with email addresses. Which statement prints the email address associated with the student id "C2104"? a. print(value of emails_dict("C2104")) b. print(key of emails_dict("C2104")) c. print(emails_dict["C2104"]) d. print(emails_dict["[email protected]"])

c. print(emails_dict["C2104"])

Which print statement would display 'C:\Users\Mika\grades.txt' (without the single quotes)? a. print(r'C:\/Users\/Mika\/grades.txt') b. print(r'C:\'Users\'Mika\'grades.txt') c. print(r'C:\Users\Mika\grades.txt') d. print(r'C:\\Users\\Mika\\grades.txt')

c. print(r'C:\Users\Mika\grades.txt')

Which data type is the correct choice to store the names of all the hockey players who have scored 3 or more goals in a single game in no specific order? a. int b. tuple c. set d. list

c. set

Which statement is equivalent to the following assignment? x -= 2 + y a. x = 2 + y - x b. x = -(2 + y) c. x = x - (2 + y) d. x = x - 2 + y

c. x = x - (2 + y)

Which statement about Python is true? a. Linux and Mac computers usually do not come with Python installed. b. There are no free web-based tools for learning Python. c. Windows usually comes with Python installed. d. Developers are not usually required to pay a fee to write a Python program.

d. Developers are not usually required to pay a fee to write a Python program.

Which of the following statements removes the value 'Google' from the set, companies? companies = { 'Apple', 'Microsoft', 'Google', 'Amazon' } a. companies.pop(2) b. companies.pop('Google') c. companies.remove(2) d. companies.remove('Google')

d. companies.remove('Google')

Which statement removes entry "1G1JB6EH1E4159506" from the dictionary cars_dict? a. cars_dict["1G1JB6EH1E4159506"] = None b. cars_dict{"1G1JB6EH1E4159506"}.del() c. delete(cars_dict["1G1JB6EH1E4159506"]) d. del cars_dict["1G1JB6EH1E4159506"]

d. del cars_dict["1G1JB6EH1E4159506"]

The _____ is a process that manages programs and interfaces with peripherals. a. clock b. BIOS c. integrated circuit d. operating system

d. operating system

What is the result of the expression: int('1750.0')? a. An error: the string does not represent an integer value b. The value 1750 as an int c. The value 1750.0 as a float d. The value '1750' as a string

a. An error: the string does not represent an integer value

With the logic block shown below, what is output when grade is assigned with the value 75? If grade < 50 Put "F" to output Else If grade < 60 Put "D" to output Else If grade < 75 Put "C" to output Else If grade < 85 Put "B" to output Else If grade <= 100 Put "A" to output Else Put "Invalid grade" to output a. A b. B c. C d. Invalid grade

b. B

What is the value of test_val after the following code is executed? a = 12 test_val = 6 if a * 2 == test_val: a = a + 7 else: test_val = 2 * a test_val = a + 1 a. 7 b. 13 c. 24 d. 25

b. 13

Which code example is an expression? a. x = 4 b. print(x) c. (x * y) / 2 d. # Display x

c. (x * y) / 2

Which expression is equivalent to: not x and y == a and b? a. (not (x and y)) == (a and b) b. ((not x) and y) and (a and b) c. not ((x and (y == a)) and b) d. ((not x) and (y == a)) and b

d. ((not x) and (y == a)) and b

Which input value causes "Goodbye" to be output next? x = int(input()) while x >= 0: # Do something x = int(input()) print('Goodbye') a. -1 b. 0 c. 1 d. No such value

a. -1

What is the value of x after the following code is executed? x = 15 x = x + 1 x = x * 2 x = 30 - x a. -2 b. 2 c. 15 d. 32

a. -2

What is the ending value of a when b is assigned with the value 5? a = 7 a = b + 5 if b > 5 else 0 a. 0 b. 5 c. 7 d. 10

a. 0

What is the value of x after the following code is executed? x = 17 if x * 2 <= 34: x = 0 else: x = x + 1 x = x + 1 a. 1 b. 18 c. 19 d. 35

a. 1

What sequence is generated by range(1, 10, 3) a. 1 4 7 b. 1 11 21 c. 1 3 6 9 d. 1 4 7 10

a. 1 4 7

What is the output? names = [ 'Gerry', 'Preet', 'Jimin', 'Susan' ] index = 0 while index < len(names): if names[index] == 'Susan': break else: index += 1 else: print('Done') print(index) a. 3 b. 4 c. Done d. 3 Done

a. 3

What is the output? my_list = [3, 7, 0, 2, -1, 8] index = 0 while my_list[index] > 0: print(my_list[index], end=' ') index += 1 a. 3 7 b. 3 7 0 c. 3 7 0 2 d. 3 7 0 2 -1

a. 3 7

How many times will the print statement execute? for i in range(1, 3): for j in range(8, 12, 2): print('{:d}. {:d}'.format(i, j)) a. 4 b. 6 c. 9 d. 36

a. 4

Given x = 1, y = 2, and z = 3, how is the expression evaluated? In the choices, items in parentheses are evaluated first. (x == 5) or (y == 2) and (z == 5) a. False OR (True AND False) --> False OR False --> False b. False OR (True AND False) --> False OR True --> True c. (False OR True) AND False --> True AND False --> False d. (False OR True) AND False --> True AND False --> True

a. False OR (True AND False) --> False OR False --> False

Which is an essential feature of a while loop having the following form? while loop_expression: loop_body a. The loop_expression should be affected by the loop_body b. The loop_expression should not be affected by the loop_body c. The loop_body should get user input d. The loop_body should update at least two variables

a. The loop_expression should be affected by the loop_body

What is the output? names = ['Bob', 'Jill', 'Xu'] ages = [24, 18, 33] for index in [2, 0, 1]: print(names[index] + ":" + str(ages[index])) a. Xu:33Bob:24Jill:18 b. Bob:24Jill:18Xu:33 c. Xu, Bob, Jill:33, 24, 18 d. Xu:24Bob:18Jill:33

a. Xu:33Bob:24Jill:18

Which determines if user_unit is in the list accepted_units? accepted_units = [ 'in', 'cm', 'mm', 'km', 'miles' ] a. if user_unit in accepted_units: b. if accepted_units in user_unit: c. if user_unit == (accepted_units): d. if user_unit == x in accepted_units:

a. if user_unit in accepted_units:

What condition should replace ZZZ to output "Same name" only if the values of two variables are the same? my_name = input("Enter my name: ") your_name = input("Enter your name: ") if ZZZ: print("Same name") a. my_name == your_name b. my_name = your_name c. my_name is your_name d. id(my_name) == id(your_name)

a. my_name == your_name

Which expression can be used to decide if x is not between 10 and 20? a. not (10 < x < 20) b. not (x < 10 and x < 20) c. not (x < 10 or x < 20) d. not (x > 10 or x < 20)

a. not (10 < x < 20)

What is the missing function name so that the output is: Cairo New York Paris Sydney? cities = ['Sydney', 'Paris', 'New York', 'Cairo'] for c in _____(cities): print(c, end=' ') a. reversed b. backwards c. list d. inverse

a. reversed

Which expression is equivalent to the following code? if age < 18: x = x + 5 else: x = x + 1 a. x = x + 5 if age < 18 else x + 1 b. x = x + 5 if age >= 18 else x + 1 c. if age < 18 x = x + 5 else x = x + 1 d. x = x + 1 else if age < 18 x + 5

a. x = x + 5 if age < 18 else x + 1

What is x's final value? x = 10 y = 20 if y <= 2 * x: x = x + 5 else: x = x * 2 a. 10 b. 15 c. 20 d. 25

b. 15

What is the ending value of z? z = 0 a = 5 while a > 0: a = a - 1 if a == 2: continue z = z + a a. 7 b. 8 c. 9 d. 10

b. 8

Which of the following loops is best implemented with a for loop? a. Asking a user to enter names until the user enters 'Quit'. b. Counting the number of negative values in a list of integers. c. Starting from a user-entered integer, increment the value until the value is a prime number. d. Reading values from a temperature sensor until it gives a value greater than 100 degrees.

b. Counting the number of negative values in a list of integers.

A programmer must write a program that lists all the words that appear in a text file that occur more than 10 times. Which of the following tasks would be a good first step in an incremental programming process? a. Display a list of all the unique words in the file. b. Display the file's contents. c. Display a table of all the words in the file, with how many time that word occurs. d. Write any import statements needed for the program, and print "Done Step 1".

b. Display the file's contents.

Which formatting presentation type is used to display an integer? a. i b. d c. :d d. (int)

b. d

The built-in Python function that gives an object's identity is: a. memory() b. id() c. type() d. identity()

b. id()

What is the ending value of x? x = 0 i = 5 while i > 1: x = x + i i = i - 1 a. 0 b. 12 c. 14 d. 15

c. 14

What is the output? x = 18 while x % 3 == 0: print(x, end=' ') x = x // 3 a. 6 b. 6 2 c. 18 6 d. 18 6 2

c. 18 6

What is the final value of z? grades = { 'A': 90, 'B': 80, 'C': 70, 'D': 60 } my_grade = 70 if my_grade not in grades: z = 1 else: z = 2 if 'F' in grades: z = z + 10 else: z = z + 20 a. 11 b. 12 c. 21 d. 22

c. 21

What is the ending value of count? my_list = [3, -4, 0, -1, 2, 1, 8] n = 0 count = 0 While n < length of my_list: If my_list[n] > 0 count = count + 1 n = n + 1 a. 1 b. 3 c. 4 d. 5

c. 4

How many times does the following loop iterate? i = 5 while i < 10: print(i) i = i + 1 a. 0 b. 4 c. 5 d. 6

c. 5

How many times will the body of the loop be executed? number = 70 guess = 55 while number != guess: if number > guess: guess = guess + 10 else: guess = guess - 1 print('The number is:', guess) a. 2 b. 3 c. 7 d. 15

c. 7

What is the value of x after the following code is executed? x = 7 If x < 7 x = x + 1 x = x + 2 a. 7 b. 8 c. 9 d. 10

c. 9

Which input for variable c causes "Done" to be output next? c = 'y' while c == 'y': # Do something print('Enter y to continue, n to quit: ', end=' ') \ c = input() print('Done'); a. 'y' only b. 'n' only c. Any value other than 'y' d. No such value (infinite loop)

c. Any value other than 'y'

Which is true of the badly formatted code? x = input() if x == 'a': print('first') print('second') a. Both print() statements must be indented. b. Neither print() statement has to be indented. c. The first print() statement must be indented. d. The second print() statement can't be indented.

c. The first print() statement must be indented.

The following program prints the number of integers in my_list that are greater than the previous integer in the list. Which choice fills in the blank to complete the for loop? my_list = [ 3, 2, 7, 8, 6, 9 ] count = 0 for _____: if my_list[i] > my_list[i-1]: count = count + 1 print(count) a. i in range(0, len(my_list)) b. i in range(0, len(my_list)+1) c. i in range(1, len(my_list)) d. i in range(1, len(my_list)+1)

c. i in range(1, len(my_list))

If x = 10 and y = 20, which expression is True? a. x == y b. y <= x c. y >= x d. y != 2 * x

c. y >= x

What is the output? id_list = [13, 984, 231, 140] for id in id_list: if id != 231: print(id, end=' ') else: print('Done') a. Done b. 13 984 Done c. 13 984 231 140 Done d. 13 984 140 Done

d. 13 984 140 Done

What is displayed when the following code is executed? day = 23 if day % 10 == 1: ending = "st" elif day % 10 == 2: ending = "nd" elif day % 10 == 3: ending = "rd" else: ending = "th" print(str(day) + ending) a. 23th b. 23st c. 23nd d. 23rd

d. 23rd

How many times does the following loop iterate? i = 0 while i <= 100: print(i) i = i + 2 a. 0 b. 49 c. 50 d. 51

d. 51

What is the output? count = 0 while count < 3: print('loop') count = count + 1 print('final value of count:', count) a. Prints 'loop' once, then 'final value of count: 1' b. Prints 'loop' three times, then 'final value of count: 3' c. Prints 'loop' three times, then 'final value of count: 4' d. Prints 'loop' forever (infinite loop)

d. Prints 'loop' forever (infinite loop)

What is the output? c1 = 'c' while c1 > 'a': for i in range(3): print('{:s}{:d}'.format(c1, i), end=' ') c1 = chr(ord(c1) - 1) a. c1 c2 c3 b1 b2 b3 b. c2 c1 c0 b2 b1 b0 c. c0 c1 c2 b0 b1 b2 a0 a1 a2 d. c0 c1 c2 b0 b1 b2

d. c0 c1 c2 b0 b1 b2

Which XXX / ZZZ outputs every name/grade pair in the dictionary, as in: Jennifer: A? grades = { 'Jennifer' : 'A', 'Ximin' : 'C', 'Julio' : 'B', 'Jason' : 'C' } for XXX: print(ZZZ) a. name in grades / name + ': ' + grade b. grade in grades / name[grades] + ': ' + grade c. name in names / grades[name] + ': ' + grades[grade] d. name in grades / name + ': ' + grades[name]

d. name in grades / name + ': ' + grades[name]

Which print statement would display: I won't quit! a. print('I won\\'t quit!') b. print('I won't quit!') c. print('I won\'\t quit!') d. print('I won\'t quit!')

d. print('I won\'t quit!')

A _____ is a named item used to hold a value. a. constant b. number c. statement d. variable

d. variable

The special two-item character sequence that represents special characters like \n is known as a(n) _____. a. backslash code b. escape sequence c. unicode spec d. literal character

b. escape sequence

Which data type is the correct choice to store a student's test scores in chronological order? a. string b. list c. set d. dict

b. list

Which expression calculates the average of first_num and second_num? first_num = input('Enter the first number: ') second_num = input('Enter the second number: ') a. (float(first_num) + float(second_num)) / 2 b. float((first_num + second_num) / 2) c. (first_num + second_num) / 2 d. float(first_num / 2) + float(second_num / 2)

a. (float(first_num) + float(second_num)) / 2

Which floating-point literal correctly represents the scientific notation value: 2.3 x 10^7? a. 2.3e7 b. 2.3*10e7 c. 2.3e10^7 d. 2.3xe7

a. 2.3e7

What is the output? my_list = [2, 8, 3, 1, 18, 5] print(my_list[3] + my_list[1] * 2) a. 7 b. 10 c. 17 d. 18

c. 17

Which of the following is not a valid expression? Assume x and y are integer variables. a. x / (y * 7) b. y / x * 2 c. 2x + 3y d. (x - 3*y)

c. 2x + 3y

_____ is the process where objects that are no longer needed are deleted. a. Identity recycling b. Memory clearing c. Garbage collection d. Object recycling

c. Garbage collection

RAM is an abbreviation that stands for: a. Real Analog Memory b. Ranged Access Memory c. Random Access Memory d. Random Abbreviated Memory

c. Random Access Memory

What is Moore's Law? a. A processor used in cold weather is more likely to fail b. Every action has an equal and opposite reaction c. The capacity of ICs doubles roughly every 18 months d. Any given program will become obsolete

c. The capacity of ICs doubles roughly every 18 months

What are the contents of names_list after the following code is executed? names_list = ['one', 'two', 'three'] digits_list = ['1', '2', '3'] names_list = names_list + digits_list a. ['1one', '2two', '3three'] b. ['two', 'four', 'six'] c. ['one', 'two', 'three', '1', '2', '3'] d. ['1', '2', '3', 'one', 'two', 'three']

c. ['one', 'two', 'three', '1', '2', '3']

Assume a and b are variables that hold the base and height of a right triangle. The length of the long side (hypotenuse) is calculated as the square root of a^2 + b^2. Which expression calculates the length of the hypotenuse? a. math.square_root(a * a + b * b) b. math.sqrt(math.pow(a * a), math.pow(b * b)) c. math.sqrt(math.pow(a, 2)) + math.pow(b, 2))) d. math.pow(math.sqrt(a), 2) + math.pow(math.sqrt(b), 2)

c. math.sqrt(math.pow(a, 2)) + math.pow(b, 2)))

Which statement does not print a newline character at the end? a. print('First part...') b. print('First part...\n') c. print('First part...', end='') d. print('First part...', end="-\n")

c. print('First part...', end='')

Which symbol is used in Python to create a comment? a. * b. C c. // d. #

d. #

If text_line = 'one fish two fish', what is the value of text_line[6]? a. ' ' b. 'h' c. 'i' d. 's'

d. 's'

Which of the following data values is best represented with a floating point variable? a. The number of pets in a house. b. The number of acorns in a tree. c. The number of children in a classroom. d. The speed of a snail.

d. The speed of a snail.

Which of the following symbols can be used as part of an identifier? a. @ b. $ c. & d. _ (underscore)

d. _ (underscore)

The operator *= is called a(n) _____ operator. a. double b. compound c. increment d. multiple assignment

b. compound

The formula for calculating the amount of interest charged on a loan is: interest = [principal x rate] of interest x time Which Python statement correctly performs the interest calculation? a. interest = [principal * rate_of_interest] * time b. interest = principal * rate of interest * time c. interest = principal x interest x time d. interest = (principal * interest) * time

d. interest = (principal * interest) * time

Which line in the following program causes a runtime error? sales = { "apples": 0, "lemonade": 0 } sales["apples"] = sales["apples"] + 1 del sales["lemonade"] print(len(sales["apples"])) a. sales = { "apples": 0, "lemonade": 0 } b. sales["apples"] = sales["apples"] + 1 c. del sales["lemonade"] d. print(len(sales["apples"]))

d. print(len(sales["apples"]))

Which expression gives the number of whole minutes that corresponds to some number of seconds? a. seconds % 60 b. seconds / 60 c. seconds * 60 d. seconds // 60

d. seconds // 60

Which of the following statements produces an error? Assume string_1 = 'abc' and string_2 = '123'. a. string_2 = string_1 b. string_1 = string_2 + "456" c. print(string_1 + string_2) d. string_1[1] = 'B'

d. string_1[1] = 'B'

Space, tab, and newline are all called _____ characters. a. noprint b. symbol c. space-line d. whitespace

d. whitespace

What values are in result_set after the following code is run? my_set = {1, 2, 3, 4, 5, 6} other_set = {2, 4, 6} result_set = my_set.union(other_set) a. { } b. {1, 3, 5} c. {2, 4, 6} d. {1, 2, 3, 4, 5, 6}

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


Related study sets

prep u : Med Surg ch 3 - Critical Thinking, Ethical Decision Making, and the Nursing Process, ch. 4 - Health Education and Health Promotion

View Set

Business Management - Brand Promise

View Set

Final Exam Chapter 13, 14, 15, and 16

View Set

Intro to Psych Unit 1 Test (1-5)

View Set

Quiz: Third-Party Policy Ownership

View Set