Midterm

¡Supera tus tareas y exámenes ahora con Quizwiz!

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

%

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)

2x + 3y

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

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

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

D

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

D. *

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 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

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 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:

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

a. or

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 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])

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 name of the data type used for floating point numbers? a.float b.decimal c.non_integer d.floating_point

a. float

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 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 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

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

a. Max_age

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

a. argument

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

a. associative

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:

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 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))

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

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

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

a.4

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 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

A sequence of instructions that solves a problem is called

algorithm

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

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 > 20 ZZZ: user_age > 10

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

Which expression for YYY will result in an output of "Pass" only if x is exactly 32? if YYY: print('Pass') else: print('Fail') a.x != 32 b.x == 32 c.x >= 32 d.x <= 32

b. x == 32

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 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)

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

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 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

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

b. x = -(2 + y)

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

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

b. overflow

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 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

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.

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'

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

When was Jen unemployed? if (year >= 2010 and year <= 2014): print('Jen employed at Regal Cinemas') elif (year >= 2018): print('Jen employed at AMC Cinemas') else: print('Unemployed') a.Before 2010 and from 2014 to 2018 b.2014 to 2018 c.Before 2010 and from 2015 to 2017 d.2015 to 2017

c. Before 2010 and from 2015 to 2017

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 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 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

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

c. 1.0

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

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))

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 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

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

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 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'

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

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

d

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 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

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

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

or what values of integer x will Branch 3 execute? If x < 10 : Branch 1 Else If x > 9: Branch 2 Else: Branch 3 a.Value 10 or larger b.Value 10 only c.Values between 9 and 10 d.For no values (never executes)

d. For no values (never executes)

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')

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

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'

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

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

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

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

d. variable

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 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(f'{i}. {j}') a.3 b.10 c.13 d.30

d.30

What is the output? c1 = 'c' while c1 > 'a': for i in range(3): print(f'{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

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

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

garbage collection

which instruction displays variables or expression values?

print()


Conjuntos de estudio relacionados

3328 Data Analytics and Visualization

View Set

BNAD 277 EXAM 1 CONCEPTUAL REVIEW QUESTIONS

View Set

AP Environmental Science Test - Missed Questions

View Set

07 - Project Cost Management - 4

View Set

Chapter 22: Neurodevelopmental Disorders

View Set