cosc 1336 exam 3

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

Which correctiy passes two integer arguments for the function call calc_val(.)?

(99, 44 + 5)

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

(k, i + j, 99)

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

(x,y)

What is the value of my_str after the following statements are evaluated: my_str http:/reddit.com/r/python

/r/python

for i in num if i % 2 == 1 cnt_odd +=1

0

Assume the function below is defined: x def split check(amount, num people, tax 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.

0.07

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

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 assigned for the following call? Type ERROR if the call is invalid. split_ check(amount=49.50, num people=3)

0.095

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

00150

What is the output of print? print('%05.lf' % 75.55)

075.5

def print_sum (num1,num2): print(num1, ' +' ,num2, 'is' (num1,num2)) print (num] What will be printed for the following function call? print sum(l, 2)

1 + 2 is 3

Given the list nums = ([10, 20, 301, [98, 99]], what does nums[0][0] DoInts evaluate to

10

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

assume a function def print num(user num): simply prints the value or user_num without any space or newline. What will the following code output: print_num(43) print_num(21)

4321

For any call to bay_fee(), how many assignment statements will execute?

5

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)

55

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

77

Assume the variable my_str is "Agt23afc2kjMhagrds!". What is the result of the expression my_str[0:5:1]?

Agt2t

A key reason for creating functions is to help the program run faster

False

A local variable's scope extends from a function definition's ending colon "." to the end of the function.

False

A programmel can pass only string arguments to a user-defined function.

False

Assignments to a parameter name inside a function affect the code outside the function.

False

Function convert _to_pres() would likely return (temp * volume) / (mols * gas_constant)

False

Given: x def square root (x): return math.sqrt(x) def print_val(x): print(x) Is the following statement valid? y = square_root(49.0)

False

Is the following a valid function definition beginning? def_my_fct(userNum + 5)

False

Is the following statement valid? y = square_root()

False

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

False

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

False

The result of evaluating nums[0:5:2] is [25, 75].

False

avoiding redundancy means to avoid calling a function from multiple places in a program.

False

gas constant - 8.3144621 # Joules / (mol*Kelvin) def convert to temp pressure, volume, MO_S). "Convert pressure, Volume, and moles to a temperature" return pressure * volume mo13 as conscant (input ("Enter pressure (in Pascals) tr enter volume (in cubic meters). flastlinou cer number of mole print Temperature = 3026 rt to temp bre 58, Vol, mole

False

my_str = 'The cat in the hat' print(my_str[0:3])

The

A local variable is defined inside a function, while a global variable is defined outside any function.

True

A namespace is how the Python interpreter restricts variables to a specific scope.

True

A program can modify the elements of an existing list.

True

Copying-and-pasting code can lead to common errors if all necessary changes are not made to the pasted code

True

Forgetting to return a value from a function is a common error.

True

Functions are compiled into bytecode when the function definition is evaluated by the interpreter.

True

Incremental development may involve more frequent testing,but ultimately leads to faster development of a program.

True

Polymorphism refers to how an operation depends on the involved object types.

True

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

True

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]

nums = [1, 1, 2, 3, 5, 8, 13] What is the result of nums[1:5]?

[1, 2, 3, 5]

Complete the function definition requiring two arguments arg1 and arg2, and an arbitrary argument list args.

arg1, arg2, *args

Which of the following are correct function definition beginnings? The correct answer may involve more than one choice.

def compute_sum (a,b,c):

{* 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 the results are averaged together. To decrease the potential for bias, the highest and lowest scores are removed before taking the average of the remaining. A working solution was constructed to compute and return the average, but after a system crash, the file was scrambled. Unscramble the code below to reconstruct the required functionality. average = total/len(score_list) def compute_average(score_list): return average score _list = score _list[1:-1] score_list.sortO total = sum(score_list) What is the first instruction? Type it in the box below.

del compute_average(score_list):

Given the following program, select the namespace that each name would belong to import random player name = 'Gandalf'' player type = 'Wizard' def roll(): """Returns a roll of a 20-sided die""" number = random.randint(1, 20) return number print ('A troll attacks!') troll_roll = roll() player_roll = roll() print('Player: %5 Troll: %s' % (str(player_roll), str(troll_roll)

local

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

num1 + num2

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

print_age(21)

Given 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 (providing the arguments in that order).

print_sum(x, 400)

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 the results are averaged together. To decrease the potential for bias, the highest and lowest scores are removed before taking the average of the remaining. A working solution was constructed to compute and return the average, but after a system crash, the file was scrambled. Unscramble the code below to reconstruct the required functionality. 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? Type it in the box below.

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

1 10 out of 10 points 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 the results are averaged together. To decrease the potential for bias, the highest and lowest scores are removed before taking the average of the remaining. A working solution was constructed to compute and return the average, but after a system crash, the file was scrambled. Unscramble the code below to reconstruct the required functionality. average = total/len(score_list) def compute _average(score _list): return average score _list = score list[1:-1] score _list.sorto total = sum(score_list) Which instruction eliminates the lowest and highest score? Type it in the box below.

score list = score_ilsti[1: -1]

Write a statement that assigns str2 with a copy of strt.

str2 = str1[:]

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

user_age

Which of the following statements correctly passes two arguments in the call to the function whatsthis(a,b). The correct answer may involve more than one choice.

whatsthis("This", "is easy") whatsthis(a*3, a-3) whatsthis("Time" + "after time") whatsthis("cat", [4,5])


Conjuntos de estudio relacionados

Forensic Science Semester Exam Test

View Set

Hot Words for the SAT (Lesson 14 - No Get Up or Go! - Words Relating to Lacking Energy or Movement)

View Set

Natural Language Processing Final Exam

View Set

Determining Chemical Formulas Chemistry

View Set