pythonSC
Given a function definiton
and given a call to the function
What is a formal parameter? What is the actual parameter?
formal parameter : n
actual parameter : 20
If you call the above function as
what is the value of y?
170
What is the difference between
and
Double is function name a callable name.
Double(20) is a funtcion call
If you do
What happens, and what is the value of z?
It prints out 'enter a name: ', z = None
Given the function
What does this function return?
return a tuple(a // b, a % b)
Are the following pairs equivalent (in terms of parameters received by the open() function for opening files)?
Consider the function declaration
Can you call this function in the following ways? If so, what is the result? If not, why not?
Suppose you are given a function
What does the following code sequence print?
In other words, does the parameter rate's default value get changed on line 3 such that the next call gets the modified default value?
No
Are you allowed to define default values with non-constant expressions such as the following? If so, what does it do?
Suppose you have a function declared as
What is the value of rate and priceTags inside the function totalTax when you call it as
Given the following function definition:
Are the following valid ways of calling the function? If so, what are the values of parameters rate and priceDict while inside the totalTax function, and what is the corresponding return value? If not valid, why not?
Given the following function definition
Are the following valid ways of calling the function? If so, what are the values of parameters rate, items, and priceDict while inside the totalWithTax function, and what is the corresponding return value? If not valid, why not?
Suppose you have two tuples
and you want to use the built-in function max() to find the largest element in the two tuples. Which of the following will correctly find the answer (which is 8)? Choose all that apply and explain why or why not.
Given the following code
What is printed when you run this code?
3
Given the following code
What is printed when you run this code?
Given the following code
But it gives an UnboundLocalError when you try to run it.
Why do you get this error?
there is no variable a in function namespace
How do you fix it if you want the function F to use the identifier a as defined on line 1?
Given the source code
ββββββββAre the following valid ways of calling the function totalWithTax? If so, what are the values of parameters names, and kv while inside the totalWithTax function, the values of the global variable D, and what is the corresponding return value? If not valid, why not? Assume you reload the code each time before executing the code below.
How do you write test code at the end of a module to test functions defined in the module when it is run as a top-level module (hint: 'main'), but don't run the test case when it is imported by another module? Also, what construct should you use to check if a tested function returns the results as the correct answer?