Computer Science
Consider the code given below:
b = 100
def test(a):
............... #missing statement
b = b + a
print(a, b)
test(10)
print(b)
Which of the following statements should be given in the blank for #Missing Statement, if the output produced is 110?
- global a
- global b = 100
- global b
- global a = 100
Python Functions
3 Likes
Answer
global b
Reason — When we want to modify a global variable within a function in Python, we need to use the global keyword followed by the name of the global variable. In this case, since the variable b is declared as a global variable outside the function, we need to declare it as a global variable again inside the function using global b before attempting to modify its value.
Answered By
1 Like
Related Questions
What possible outputs(s) will be obtained when the following code is executed?
import random myNumber = random.randint(0, 3) COLOR = ["YELLOW", "WHITE", "BLACK", "RED"] for I in range(1, myNumber): print(COLOR[I], end = "*") print()- RED*
WHITE*
BLACK* - WHITE*
BLACK* - WHITE* WHITE*
BLACK* BLACK* - YELLOW*
WHITE*WHITE*
BLACK* BLACK* BLACK*
- RED*
Fill in the blank:
The modem at the sender’s computer end acts as a …………… .
- Model
- Modulator
- Demodulator
- Convertor
State whether the following statement is True or False:
An exception may be raised even if the program is syntactically correct.
Which of the following statements is FALSE about keys in a relational database?
- Any candidate key is eligible to become a primary key.
- A primary key uniquely identifies the tuples in a relation.
- A candidate key that is not a primary key is a foreign key.
- A foreign key is an attribute whose value is derived from the primary key of another relation.