COSC 1306 Exam 3

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Given the following program, select the namespace that each name would belong to: str

Built-in

[Refer to convert_to_temp function] Function convert_to_pres() would likely return (temp * volume) / (mols * gas_constant).

FALSE

[Refer to function trajectory] Each iteration of the loop will see y_loc increase.

FALSE

[Refer to function trajectory] The program could replace float() by int() without causing much change in computed values.

FALSE

square_root(49.0) = z

FALSE

y = 1 + print_val(9.0)

FALSE

y = square_root()

FALSE

Given the following program, select the namespace that each name would belong to: player_name

Global

Given the following program, select the namespace that each name would belong to: roll

Global

What is the output? print('%4s %08d' % ('ID:', 860552))

ID: 00860552

Given the following program, select the namespace that each name would belong to: number

Local

Is the following a valid function definition beginning? Yes or no. def my_fct(userNum + 5):

No

[eBay Fee Code] Write a function call using the ebay_fee() function to determine the fee for a selling price of 15.23, storing the result in a variable named my_fee.

my_fee = ebay_fee(15.23)

Add a return statement to the function that returns the cube of the argument (num * num * num) def cubed(num(: return_____

num * num * num

Add 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, passing the value 21 as an argument.

print_age(21)

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

reddit.com/r/python

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

str2 = str1[:]

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

user_age

Write a statement that joins all the elements of my_list together, without any separator character between elements.

''.join(my_list)

[print_face Code] How many function calls to print_face are there?

2

[print_face Code] How many print statements exist in the program code?

3

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

4321

[eBay Fee Code] For any call to ebay_fee(), how many assignment statements will execute?

5

Given the function definition: def calc_val(a, b, c):, What value is assigned to b during this function call: calc_val(42, 55, 77)?

55

[print_face Code] How many print statements would execute in total?

6

[eBay Fee Code] What does ebay_fee() return if its argument is 100.0 (show your answer in the form #.#)?

9.5

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

ERROR

The following function is defined: def split_check(amount, num_people, tax_rate = 0.095, tip_rate = 0.15) What will the parameter num_people be assigned for the following call? Type ERROR if the call is invalid. split_check(12.50, tip_rate = 0.18)

ERROR

The following function is defined: def split_check(amount, num_people, tax_rate = 0.095, tip_rate = 0.15) What will the parameter num_people be assigned for the following call? Type ERROR if the call is invalid. split_check(tip_rate = 0.18, 12.50, 4)

ERROR

'1 2 3 4 5'.isdigit()

FALSE

'HTTPS://google.com'.isalnum()

FALSE

A function may return multiple objects.

FALSE

A global statement must be used whenever a global variable is to be read or written in a function.

FALSE

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 programmer can pass only string arguments to a user-defined function.

FALSE

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

cat

A pass statement should be used in a function stub when the programmer wants the stub to stop program execution when called.

FALSE

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

FALSE

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

FALSE

If a function's internal statements are revised, all function calls will have to be modified too.

FALSE

If a programmer defines a function named list(), the program will crash because there is already a built-in function with the same name.

FALSE

If my_func1() and my_func2() are defined functions, then the expression my_func1 + my_func2 returns a valid value.

FALSE

The expression my_func1(my_func2()) passes the my_func2 function object as an argument to my_func1.

FALSE

The main advantage of function stubs is that they ultimately lead to faster-running programs.

FALSE

The output of the following program is 'meow': def cat(): print('meow') def pig(): print('oink') cat = pig cat()

FALSE

The same name cannot be in multiple namespaces.

FALSE

When a function is called, copies of all the argument objects are made.

FALSE

'HTTPS://google.com.startswith('HTTP')

TRUE

'LINCOLN, ABRAHAM'.isupper()

TRUE

'\n\n'.isspace()

TRUE

A dynamic-typed language like Python checks that an operation is valid when the operation is executed by the interpreter. If the operation is invalid, a run-time error occurs.

TRUE

A function definition must be evaluated by the interpreter before the function can be called.

TRUE

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 programmer can protect mutable arguments from unwanted changes by passing a copy of the object to a function.

TRUE

Adding an element to a dictionary argument in a function might affect variables outside the function that reference the same dictionary object.

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 compiled into byte code 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

Returning the incorrect variable from a function is a common error.

TRUE

Static-typed languages require that the type of every variable is defined in the source code.

TRUE

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

TRUE

Whenever a function in called, a local namespace is created for that function.

TRUE

[Refer to convert_to_temp function] Function convert_to_temp uses a global variable for the gas constant R.

TRUE

[Refer to convert_to_temp function] Function convert_to_temp uses a written form of PV = nRT to solve for T, namely T = PV/nR.

TRUE

[Refer to function trajectory] Assuming the launch angle is less than 90 degrees, each iteration of the loop will see x_loc increase.

TRUE

[Refer to function trajectory] trajectory() cannot return two values (for x and y), so instead returns a single tulle containing both x and y.

TRUE

print_val(9.0)

TRUE

square_root(9.0)

TRUE

y = 1.0 + square_root(144.0)

TRUE

y = print_val(9.0)

TRUE

y = square_root(49.0)

TRUE

y = square_root(square_root(16.0))

TRUE

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

The

Write a statement that uses the join() method to set my_str to 'NewYork' using the list x = ['New', 'York'].

my_str = ''.join(x)

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

print_sum(x, 400)

Assume the function below is defined: def split_check(amount = 10, num_people = 2, tax_rate = 0.095, tip_rate = 0.18): Write a statement that splits a $25 check among 3 people and leaves a 25% tip. Use the default tax_rate.

split_check(amount=25, num_people=3, tip_rate=0.25)

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

Write a statement that uses the join() method to set my_str to 'images.google.com', using the list x= ['images', 'google', 'com'] my_str = _____

'.'.join(x)

Complete the function call so that the output of the program is: John is: age:10 gender: m def stats(name, **info): print(name, 'is:') for key, value in info.items(): print('%s: %s' % (key, value)) stats(_____)

'John', age=10, gender='m'

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

(99, 44 + 5)

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

(k, i + j, 99)

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

(x, y)

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.

0.07

Assume the function below is defined: def split_check(amount = 10, num_people = 2, tax_rate = 0.095, tip_rate = 0.18): 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

The following function is defined: 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

The following function is defined: 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.125)

0.125

[eBay Fee Code] What does ebay_fee() return if its argument is 0.0 (show your answer in the form #.#)?

0.5

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

00075

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

00150

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

075.5

[print_face Code] How many function definitions of print_face are there?

1

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

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

Agt2t

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

AttackMars

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

arg1, arg2, *args

Assume the function below is defined: def split_check(amount = 10, num_people = 2, tax_rate = 0.095, tip_rate = 0.18): Write a statement that splits a $50 check among 4 people. Use the default tax rate and tip amount.

split_check(amount=50, num_people=4)


Kaugnay na mga set ng pag-aaral

Cognitive Psychology Exam 4 / Final

View Set

ATI Targeted Med Surg - Cardiovascular

View Set

Chapter 7 Managerial Accounting: Activity-Based Costing: A Tool to Aid Decision-Making

View Set