cpsc 150 quizzes

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

If text_line = 'one fish two fish', what is the value of text_line[7]? 'i' 's' 'h' ' '

'h'

If text_line = 'one fish two fish', what is the value of text_line[5]? 'h' 's' ' ' 'i'

'i'

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 19 18 35 1

1

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

2) Xu:33 Bob:24 Jill:18

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

51

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

7

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

9

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

The element at index 1 is 'JFK'

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 ['1', '2', '3', 'one', 'two', 'three'] ['two', 'four', 'six'] ['1one', '2two', '3three'] ['one', 'two', 'three', '1', '2', '3']

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

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

_ (underscore)

Which correctly calls the add() function? def add(a, b, c): print(a + b + c) add(2 + 4 + 6) add(2; 4; 6) add(2, 4, 6) add(2 4 6)

add(2, 4, 6)

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

companies.remove('Google')

Which of the following lines of code is not valid, given the definitions of the cubed() and display() functions? def cubed(x): return x * x * x def display(x): print(x) display(cubed(2.0)) display('Test') cubed(x) = 8.0 y = cubed(2.0)

cubed(x) = 8.0

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

escape sequence

Which variable can be used in place of XXX in the following code? def fahrenheit_to_celsius(f): fraction = 5 / 9 c = (f - 32) * fraction print(c) degrees = float(input('Enter degrees in Fahrenheit: ')) fahrenheit_to_celsius(XXX) f degrees fraction c

f

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

fruits_dict["Lemon"] = 0.75

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

key

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

len(my_list)

Which XXX will display one more than half of the smallest value of w1, w2, and w3? def min_value(a, b, c): if a<=b and a<=c: return a elif b<=a and b<=c: return b else: return c w1 = 7 w2 = 3 w3 = 12 y = XXX print(y) min_value: w1, w2, w3()/2 + 1 min_value(w1 + 1, w2 + 1, w3 + 1)/2 min_value(w1, w2, w3)/2 + 1 min_value()/2 + 1, w1, w2, w3

min_value(w1, w2, w3)/2 + 1

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

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

In the following code, the variable size is the function's _____. def print_square_area(size): area = size * size print("A square of size {} has area {}".format(size, area)) s = float(input('Enter size of square: ')) print_square_area(s) argument value parameter property

parameter

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

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

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"? print(emails_dict["C2104"]) print(emails_dict.val("C2104")) print(emails_dict.key("C2104")) print(emails_dict["[email protected]"])

print(emails_dict["C2104"])

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"]))? sales = { "apples": 0, "lemonade": 0 } sales["apples"] = sales["apples"] + 1 del sales["lemonade"] print(len(sales["apples"]))

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

Which print statement would display the value 68? (Note that the code point for the letter 'D' is 68.) print(chr('D')) print(unicode('D')) print(ord('D')) print(code_point('D'))

print(ord('D'))

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

prompt

Which XXX completes the find_smallest() function? def find_smallest(a, b, c): if a <= b and a <= c: smallest = a elif b <= a and b <= c: smallest = b elif c <= a and c <= b: smallest = c XXX result = find_smallest(7, 4, 8) print(result) return c return smallest return a return b

return smallest

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

string, immutable sequence type

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) temperatures < 0 temperatures[t] < 0 t[temperatures] < 0 t < 0

t < 0

Which statement uses the square() function to assign the variable t with 16? Note that 16 = 24 = (22)2 def square(x): return x * x t = square(2) + square(2) t = square(4) * square(2) t = square(2), square(2) t = square(square(2))

t = square(square(2))

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

user_name = input()

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

white-space

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

x + y = z

Which XXX is valid for the following code? def calc_sum(a, b): return a + b XXX print(y) y = calc_sum() y = calc_sum(4 + 5) calc_sum(y, 4, 5) y = calc_sum(4, 5)

y = calc_sum(4, 5)


Ensembles d'études connexes

SIE 8 Securities Exchange Act of 1934 and the Secondary Markets

View Set

Technology and its Effects on Modern America

View Set