Robotics & Artificial Intelligence
Predict the output of the following code:
def Disp_Max(a, b):
if a > b:
print(a, 'is maximum')
elif a == b:
print(a, 'is equal to', b)
else:
print(b, 'is maximum')
Disp_Max(22, 14)
Python Functions
3 Likes
Answer
Output
22 is maximum
Explanation
The function Disp_Max() is called with the values 22 and 14. Inside the function, the condition a > b is checked first. Since 22 > 14 is True, the statement print(a, 'is maximum') gets executed and displays 22 is maximum. The elif and else blocks are skipped because the first condition is already satisfied.
Answered By
2 Likes
Related Questions
Predict the output of the following code:
def Add(num1, num2): sum = num1 + num2 sum = Add(20, 30) print(sum)Predict the output of the following code:
def Sum(a, b): return a+5, b*5 # main program result = Sum(4, 5) print(result)Assertion (A): When the user defines a function of his/her own and use it in the program to perform a specific task, it is known as user defined function.
Reason (R): The types of functions viz. built-in functions and modules are also known as user defined functions because they are not defined by the system developers. Thus, it is not necessary that the system developers are only authorised for creating a function.
Based on the above discussion, choose an appropriate statement from the options given below:
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true and R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
- Both A and R are false.
The Fibonacci series is a sequence of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. The following program is designed to generate next five terms of the Fibonacci series, excluding 0 and 1 (i.e., first two terms of the series). The incomplete user-defined program is given as under:
def Fibo_Series(): a = 0 b = 1 count = ........... # Line 1 while(count <= ............): # Line 2 c = a + b print(.............) # Line 3 a = ............. # Line 4 b = c count = count + 1 # main program Fibo_Series()Now, complete the above program to generate next five numbers of the series as 1, 2, 3, 5, 8.