Observe the following programs carefully, and identify the error:
def create (text, freq): for i in range (1, freq): print text create(5) #function call
The function create() requires 2 parameters (text, freq), but the function call passes only 1 argument (5). This causes a TypeError for missing positional argument.
from math import sqrt, ceil def calc(): print cos(0) calc() #function call
The program imports sqrt and ceil from math module, but uses cos(0) which is not imported. The cos function needs to be imported separately or math.cos(0) should be used.
mynum = 9 def add9(): mynum = mynum + 9 print mynum add9() #function call
The variable mynum inside function add9() is treated as a local variable. Using mynum before assigning it a value causes UnboundLocalError. The global variable mynum cannot be accessed directly.
def findValue( vall = 1.1, val2, val3): final = (val2 + val3)/vall print(final) findvalue() #function call
Two errors: (1) Default parameter 'vall = 1.1' cannot come before non-default parameters val2 and val3. Default parameters must be at the end. (2) Function name is findValue() but call uses findvalue() - Python is case-sensitive.
def greet(): return("Good morning") greet() = message #function call
The statement greet() = message is invalid. A function call cannot appear on the left side of an assignment. The correct syntax is message = greet() to store the returned value.
Explanation
This question tests understanding of function parameters, scope rules, module imports, and assignment syntax in Python. Each program demonstrates a common programming error that students must identify.