English

Observe the following program carefully, and identify the error: def create (text, freq): for i in range (1, freq): print text create(5) #function call - Computer Science (Python)

Advertisements
Advertisements

Question

Observe the following program carefully, and identify the error:

def create (text, freq):
            for i in range (1, freq):
              print text
create(5)           #function call
Short/Brief Note
Advertisements

Solution

There are two errors in the given program.

  1. The function “create” is defined using two arguments, 'text' and 'freq', but when the function is called in line number 4, only one argument is passed as a parameter. It should be written ‘create(5, 4)’ i.e with two parameters.
  2. The syntax of the ‘print’ function is incorrect. The correct syntax will be ‘print(text)’.
shaalaa.com
  Is there an error in this question or solution?
Chapter 7: Functions - Exercise [Page 170]

APPEARS IN

NCERT Computer Science [English] Class 11
Chapter 7 Functions
Exercise | Q 1. a) | Page 170
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×