代做CISD 41 Practice Quiz for Exam 1代做留学生Python程序

- 首页 >> OS编程

CISD 41 Practice Quiz for Exam 1

Question 1

Consider this dictionary:

d = {'foo': 100, 'bar': 200, 'baz': 300}

What is the result of this statement:

d['bar':'baz']

It raises an exception

(200, 300)

200 300

[200, 300]

Question 2

List a is defined as follows:

a = [1, 2, 3, 4, 5]

Which of the following statements removes the middle element 3 from a so that it equals [1, 2, 4, 5]?

a[2:3] = []

a[2] = []

a.remove(3)

a[2:2] = []

del a[2]

Question 3

How can you change

num ={'one': 1, 'two': 3}

to

num ={'one':1, 'two': 2}

num[2] = 'two'

num[1] = 'two'

num['two'] = '2'

num['two'] = 2

Question 4

Complete the code to return the output

q = [17, 25, 42, 35, 47, 45]

________(min(q))

Required Output

17

display

print

output

Question 5

Select the code to return the output

[20, 23, 10]

x = [10, 8, 20, 23, 10, 9, 7]

print (x [2:5])

x = [10, 8, 20, 23, 10, 9, 7]

print (x[ 0:5])

x = [18, 8, 20, 23, 10, 9, 7]

print ( x [0:6] )

No answer text provided.

Question 6

Complete the code to number the output

# Print the number of occurences

# of the letter "s" in z

z= "classification"

print (z _________)

2

.count ("a")

.count("e")

.count ("i")

.count ("s")

Question 7

x = ["Feb", "Apr", "Dec", "May", "Jan"]

print (x ________)

2

.index ("Jan")

.index ("Dec")

.index ("Feb")

.index ("Apr")

Question 8

Which of the following are true of Python dictionaries:

Dictionaries are mutable.

A dictionary can contain any object type except another dictionary.

All the keys in a dictionary must be of the same type.

Dictionaries are accessed by key.

Dictionaries can be nested to any depth.

Items are accessed by their position in a dictionary.

Question 9

Which of the following are true of Python lists?

A given object may appear in a list more than once

All elements in a list must be of the same type

There is no conceptual limit to the size of a list

A list may contain any type of object except another list

These represent the same list:

['a', 'b', 'c']

['c', 'a', 'b']

Question 10

Which of the following statements about my_list is false?

my_list = ['JFK', 'LAX', 'MIA']

The element at index 1 is 'JFK'

The list has a length of 3

The list elements are all strings

The index of the last item in the list is 2

Question 11

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)

{ }

{1, 3, 5}

{2, 4, 6}

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

Question 12

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)

{ }

{1, 3, 5}

{2, 4, 6}

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

Question 13

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(value of emails_dict("C2104"))

print(key of emails_dict("C2104"))

print(emails_dict["C2104"])

print(emails_dict["[email protected]"])

Question 14

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

value

pair

list

key

Question 15

Which statement changes the value associated with key "Lemon" to 0.75 in the dictionary fruits_dict?

fruits_dict[0.75] = "Lemon"

fruits_dict["Lemon"] = 0.75

fruits_dict[Lemon] = 0.75

dict("Lemon") = fruits_dict[0.75]

Question 16

Which statement removes entry "1G1JB6EH1E4159506" from the dictionary cars_dict?

cars_dict["1G1JB6EH1E4159506"] = None

cars_dict{"1G1JB6EH1E4159506"}.del()

delete(cars_dict["1G1JB6EH1E4159506"])

del cars_dict["1G1JB6EH1E4159506"]

Question 17

Which XXX causes the program to output the message "Hello!"?

def print_message():

print('Hello!')

XXX

print_message

print_message()

def print_message()

print_message('Hello!')

Question 18

The code that includes the keyword "def" is called a _____.

function call

function definition

function reference

function constructor

Question 19

After a function's last statement is executed, the program returns to the next line after the _____.

import statement

function definition

function call

start of the program

Question 20

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)

parameter

argument

property

value

Question 21

Which of the following assignment statements creates a list with 4 integer elements?

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

my_list = [4]

my_list = ['1', '2', '3', '4']

my_list = integer(4)

Question 22

In the following code, the variable val is the function call's _____.

def print_square_area(size):

area = size * size

print("A square of size {} has area {}".format(size, area))

val = float(input('Enter size of square: '))

print_square_area(val)

parameter

argument

property

value

Question 23

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)

degrees

f

c

fraction

Question 24

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)

Question 25

Which of the following is true?

A function must have exactly one return statement, or no return statement at all.

A function must always have at least one return statement.

A function can only return strings and numbers, not lists or dictionaries.

A function can have any number of return statements, or no return statement at all.

Question 26

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 a

return b

return c

return smallest

Question 27

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)

y = calc_sum(4 + 5)

calc_sum(y, 4, 5)

Question 28

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+3)/2

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

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

Question 29

Which of the following is not a reason to use functions?

To avoid writing redundant code

To improve code readability

To support modular development

To make the code run faster

Question 30

How does the given function improve the code versus if no function was present?

def fahrenheit_to_celsius(fahrenheit):

return (fahrenheit - 32.0) * 5.0 / 9.0

fahrenheit = float(input())

c1 = fahrenheit_to_celsius(fahrenheit);

c2 = fahrenheit_to_celsius(32.0);

c3 = fahrenheit_to_celsius(72.0);

The use of the function makes the program run faster

The use of the function decreases redundant code

The use of the function reduces the number of variables in the code

The function does not improve the code

Question 31

Consider my_string = 'roy came third in the running race' . Which option will return 'Roy came 3rd in the running race' as the value of new_string?

new_string = my_string.title()

new_string = new_string.replace('thi', '3')

new_string = my_string[:3].title()

new_string = new_string.replace('thi', '3')

new_string = my_string.capitalize()

new_string = new_string.replace('third', '3')

new_string = my_string.capitalize()

new_string = new_string.replace('thi', '3')

Question 32

Which statement removes the last element of my_list?

my_list.pop(len(my_list)

my_list.pop(len(my_list)-1)

my_list.remove(len(my_list))

my_list.remove(len(my_list)-1)

Question 33

Which of the following methods will change the string 'Python Programming' into 'PYTHON PROGRAMMING'?

title()

isupper()

upper()

capitalize()

Question 34

Consider the list my_list = [1880, '990EZ', 'Tax Forms'] . Which statement gives '990EZ' as the output?

print(my_list[:1])

print(my_list[1])

print(my_list[2])

print(my_list[:2])

Question 35

Select the code that gives ['cat in a hat', 'fluffy dogs', 1989, 1990] as the output.

new_list = ['1000', '2000', '3000', 'cat in a hat', 'fluffy dogs']

print(new_list[-2:] + [1989, 1990])

new_list = ['cat in a hat', 'fluffy dogs','1000', '2000', '3000']

print(new_list[-2:] + [1989, 1990])

new_list = ['1000', '2000', '3000', 'cat in a hat', 'fluffy dogs']

print(new_list[-1:] + [1989, 1990])

new_list = ['1000', '2000', '3000', 1989, 1990]

print(new_list[-2:] + ['cat in a hat', 'fluffy dogs'])





站长地图