1
2
3
4
5
6
7
8
9
10
11
12
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to Trinket.
Post a review on Amazon for the paperback or the Kindle edition.
Email me to give me a compliment, complaint, or correction. I'll respond.
0,1,2,3,4,5,6,7,8,9,10,11
0
0
0
0
When a variable is introduced within a function, its _______ is local. | scope | ^ *scope *$ | |
When a variable is introduced in the main body of code, its scope is _________. | global | ^ *global *$ | |
In the following code, what is the value of y? | def x(num): a = 2 return num * a y = x(10) | 20 | 2`0 |
In the following code, two of the variables are local. Type their names, separating the names by a comma. Type them in the order in which they appear in the code. | def a(b): total = b + c return total c = 2 num = a(10) | b,total | b,total |
In the following code, what is the final value of a? | def a(): b = 2 return b a = 1 a = a() |
2 | ^ *2 *$ |
If a function defines the variable first_name as "George" and code outside the function defines the variable first_name as "Hamid", and the function code says, print(first_name), what name will display? Omit the quotation marks. | George | ^ *•*George•* *$ | |
If a function defines the variable first_name as "George" and code outside the function defines the variable first_name as "Hamid", and the main code says, print(first_name), what name will display? Omit the quotation marks. | Hamid | ^ *•*Hamid•* *$ | |
How many variables in this function can be changed by code outside the function? Enter a numeral. | def calc(a): b = 12 c = 404 result = (a / b) * c return result |
0 | ^ *0 *$ |
How many global variables are in the following function call? (Remember, a function name is a variable.) Answer with a numeral. | a(b, c, d) | 4 | ^ *4 *$ |
Below are two global variable definitions. Code a function that uses these same variable names to create local variables whose values are integers. (It's not a good idea to give local variables the same names as global variables, but this helps you understand.) Make up the name of the function and the integers. | x = "Marta" y = "Ingrid" |
def create_local_variables(): x = 1 y = 1000 |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\):\n x = -?[0-9]+\n y = -?[0-9]+ *$ |
|
c936a7a4d2 | ||
|
621c946426 |