English

What all can be possible outputs of the following code? def myfunc(x=None): result = "" if x is None: result = "No argument given" elif x == 0: result = "Zero" elif 0 < x <= 3: result = "x is between

Advertisements
Advertisements

Question

What all can be possible outputs of the following code?

def myfunc(x=None):
    result = ""
    if x is None:
    result = "No argument given"
    elif x == 0:
    result = "Zero"
    elif 0 < x <= 3:
    result = "x is between 0 and 3"
 else:
        result = "x is more than 3"
 return result
Code Writing
Advertisements

Solution

The possible outputs are:

No argument given
Zero
x is between 0 and 3
x is more than 3

For example:

  • myfunc()No argument given
  • myfunc(0)Zero
  • myfunc(2)x is between 0 and 3
  • myfunc(5)x is more than 3
shaalaa.com
  Is there an error in this question or solution?
Chapter 8: Exception Handling & Generate Functions - EXERCISE [Page 156]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 8 Exception Handling & Generate Functions
EXERCISE | Q 1. | Page 156
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×