CompSci Unit 3 Test Review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Assume the function below is defined def split_check(amount, num_people, tax_rate, tip_rate) What value is passed as the tax_rate argument in the statement split_check(60.52, 5, .07, tip_rate = 0.18)? Answer ERROR if an error occurs

.07 or 0.07

What is the value of my_str after the following statements are evaluated: my_str = 'http://reddit.com/r/python' my_str = my_str[17:]

/r/python

Fill in the missing field to complete the program. Count how mnay od numbers (cnt _off) there are cnt_odd = _______ for i in num: if i % 2 = 1 cnt_odd += 1

0

Assume the function below is defined: def split_check(amount = 10, num_people = 2, tax_rate = 0.095, tip_rate = 0.18): When entering answers, use the same number of significant digits as the default parameter values in the split_check() definition. What will the parameter tax_rate be assignment for the following call? Type ERROR if call is invalid. split_check(amount = 49.50, num_people = 3)

0.095

def split_check(amount, num_people, tax_rate = 0.095, tip_rate = 0.15) What will the parameter tax_rate be assigned for the following call? Type ERROR if the call is invalid. split_check(65.50, 3)

0.095

What is the output of print? print('%05d' % 150)

00150

What is the output of print? print('%05.1f' % 75.55)

075.5

def print_sum(num1, num2): print(num1, '+', num2, 'is', (num1 + num2)) What will be printed for the following function call print_sum(1, 2)

1 + 2 is 3

Given the list nums = [[10, 20, 30], [98, 99]], what does nums[0][0] evaluate to?

10

def print_face(): face_char = 'o' print(' ', face_char, ' ', face_char) print(' ', face_char) print(' ', face_char * 5) return Given the following program and the definition of print_face() above: print_face() print_face() How many function calls to print_face are there?

2

def print_num(user_num): simply prints the value of user_num without any space or newline. What will the following code output? print_num(43) print_num(21)

4321

def ebay_fee(sell_price): p50 = 0.13 p50_to_100 = 0.05 p1000 = 0.02 fee = 0.50 if sell_price <= 50: fee = fee + (sell_price * p50) elif sell_price <= 1000: fee = fee + (50* p50) + ((sell_price - 50) * p50_to_1000) else: fee = fee + (50 * p50) + ((1000-50)*p50_to_1000)\ + ((sell_price - 1000) * p1000) return fee selling_price = float(input('Enter item selling price (ex: 65.00):')) print('Ebay fee: $', ebay_fee(selling_price)) For any call to ebay_fee(), how many assingment statements will execute?

5

What is the output of the following program? temps = [65, 67, 72, 75] temps.append(77) print(temps[-1])

77

Assume the variable my_str is 'Agt2t3afc2kjMhagrds!'. What is the result of the expression my_str[0:5:1]

Agt2t

Determine the output of the following code: my_str = 'The cat in the hat' print(my_str[0:3])

The

What is the output of the following code? def mystery(num): result = [1] for i in range(num): result.append(result[i] * -2) return result print(mystery(2))

[1, -2, 4]

Assume that the following code has been evaluated: nums = [1, 1, 2, 3, 5, 8, 13] What is the result of nums [1:5]?

[1, 2, 3, 5]

Which correctly passes two integer arguments for the function call calc_val(...)? a) (99, 44+5) b) (99 + 44) c) (99 44)

a) (99, 44+5)

A local variable defined inside a function, while a global variable is defined outside any function a) True b) False

a) True

A namespace is how the Python interpreter restricts variable to a specific scope. a) True b) False

a) True

Copying and pasting code can lead to common errors if all necessary changes are not made to the pasted code a) True b) False

a) True

Functions are compiled into bytecode whent he function definition is evaluated by the interpreter a) True b) False

a) True

Incremental development may inolve more frequent testing, but ultimately leads to faster development of a program a) True b) False

a) True

Polymorphism refers to how an operation depends on the involved object types a) True b) False

a) True

The statement return a, b, [c, d] is valid. a) True b) False

a) True

def square_root(x): return math.sqrt(x) def print_val(x): print(x) return is the following statement valid? y = square_root(49.0) a) True b) False

a) True

import random player_name = 'Gandalf' player_type = 'Wizard' def roll(): number = random.randint(1, 20) return number print('A troll attacks!') troll_roll = roll() player_roll = roll() print('Player: %s Troll: %s' % (str(player_roll), str(troll_roll))) number a) local b) global c) built-in

a) local

Which of the following statements correctly passes two arguments in the call to the function whatsthis(a,b) a) whatsthis("This", "is easy") b) whatsthis(a*3, a-3) c) whatsthis("Time" + "after time") d) whatsthis("cat", [4,5])

a) whatsthis("This", "is easy") b) whatsthis(a*3, a-3) d) whatsthis("cat", [4,5])

Comlete the function definition requiring two arguments arg1 and arg2, and an arbitrary argument list args def f():

arg1, arg2, *args

Given a function definition: def calc_val(a, b, c): and given variables i, j, and k, which are valid arguments in the call calc_val(...) a) (i,j) b) (k, i + j, 99) c) ( i + j + k)

b (k, i+j, 99)

A key reason for creating functions is to help the program run faster a) True b) False

b) False

A local variable's scope extends from a function definition's ending colon ":" to the end of the function a) True b) False

b) False

A program can modify the elements of an existing list a) True b) False

b) False

A programmer can pass only string arguments to a user-defined function a) True b) False

b) False

Assignments to a parameter name inside a function affect the code outside the function a) True b) False

b) False

Avoiding redundancy means to avoid calling a function from multiple places in a program a) True b) False

b) False

Given the following code: nums = [0, 25, 50, 75, 100] The result of evaluating num[0:5:2] is [25, 75] a) True b) False

b) False

Is the following a valid function definition beginning? def my_fct(userNum + 5): a) True b) False

b) False

Is the function correct for squaring an integer? def sqr(a): t = a*a return a a) True b) False

b) False

Is this function correct for squaring an integer? def sqr(a): t = a*a return a a) True b) False

b) False

def square_root(x): return math.sqrt(x) def print_val(x): print(x) return Is the following statement valid? y = square_root() a) True b) False

b) False

gas_constant = 8.3144621 def convert_to_temp(pressure, volume, mols): return (pressure * volume) / (mols * gas_constant) press = float(input()) vol = float(input()) mols = float(input()) print('Temperature = %02k K' % convert_to_temp(press, vol, mols)) Function convert_to_press() would likely return (temp * volume) / (mols * gas_constant) a) True b) False

b) False

import random player_name = 'Gandalf' player_type = 'Wizard' def roll(): number = random.randint(1, 20) return number print('A troll attacks!') troll_roll = roll() player_roll = roll() print('Player: %s Troll: %s' % (str(player_roll), str(troll_roll))) player_name a) local b) global c) built in

b) global

Which correctly defines two parameters x and y for a function definition def calc_val(...):? a) (x;y) b) (x y) c) (x, y)

c) (x, y)

Given a function definition def calc_val(a, b, c): what value is assigned to b during this function call: calc val(42, 55, 77) a)Unknown b) 42 c) 55

c) 55

Which of the following are correct function definition beginnings? a) def def(s,s): b) def my function(b,c,d): c) def compute_sum(a, b, c): d) def 2computeSum(a,b):

c) def compute_sum(a,b,c)

average = total/len(score_list) def compute_average(score_list): return average score_list = score_list[1:-1] score_list.sort() total = sum(score_list) what is the first instruction?

def compute_average(score_list):

Adding a return statement to the function that returns the result of adding num1 and num2. def sum(num1, num2): return__________

num1 + num2

Call a function named print_age, passage the value 21 as an argument

print_age(21)

def print_sum(num1 + num2) print(num1, '+', num2, 'is', (num1 + num2)) Write a function call using print_sum() to print the sum of x and 400

print_sum(x, 400)

average = total/len(score_list) def compute_average(score_list): return average score_list = score_list[1:-1] score_list.sort() total = sum(score_list) what is the last instruction?

return average

Add a return statement to the function that returns the cube of the argument, i.e.(num* num* num) def cubed(num):

return num* num* num or return num**3

You have been contracted by a company to help fix a problem with an electronic score calculation system for use with subjectively-scored competitions. In events with subjective scoring several judges provide scores and results are averaged together. To decrease the potential for bias, the highest and lowest scores are removed before taking the average of the remaining. average = total / len(score_list) def compute_average(score_list): return average score_list = score_list[1:-1] score_list.score() total = sum(score_list)

score_list = score_list[1:-1]

Complete the function beginning to have a parameter named user_age def print_age():

user_age


Set pelajaran terkait

Chapter 16: Disorders of the Immune Response Prep U

View Set

Med Surg Test 5- Review Questions- Chapter 49

View Set

mechanical properties of materials

View Set

NSG 333 Ch 11- Maternal Adaptation During Pregnancy

View Set