Page 281 - Computer Science V2.0 Class 11
P. 281
>=50 and <75 <65000 4000 per month
>=65000 3000 per month
>=75 and <=100 Not to be considered 5000 per month
01 def scholarship(percentage, annualIncome):
02 """
03 Objective: To find the amount of scholarship
04 Inputs :
05 percentatage : percentage of marks
06 annualIncome : Annual Income Return value: scholarship - monthly scholarship amount
07 """
08 if percentage < 40:
09 scholarship = 'Nil'
10 elif percentage >= 40 and percentage<50:
11 if annualIncome < 65000:
12 scholarship = 2000
13 else:
14 scholarship = 'Nil'
15 elif percentage >= 50 and percentage<75:
16 if annualIncome < 65000:
17 scholarship = 4000
18 else:
19 scholarship = 3000
20 elif percentage >= 75:
21 scholarship = 5000
22 return scholarship
23 percentage = int(input("Enter your percentage : "))
24 income = int(input("Enter the annual income : "))
25 print('Monthly scholarship:', scholarship(percentage, income))
26 print("Thank You, for using this program ")
Output:
>>> Enter your percentage : 45
>>> Enter the annual income : 98000
Monthly scholarship: Nil
Thank You, for using this program
In the example given above, an if statement is nested inside another if/elif block. So, the nested if statement
will be executed only if the conditional expression of the outer if/elif statement yields True. All the statements
in a particular block are indented at the same level.
Program 10.11 Write a function max3(num1, num2, num3) that accepts from the user three numbers and
displays the largest of the three numbers.
Let us write a function that returns the largest of three numbers, (say, num1, num2, and num3). We first
compare num1 and num2. If num1 < num2, i.e., num2 is larger than num1, we compare num2 with num3.
If num2 < num3, we have found that num3 is the largest of the three numbers. However, in the other case
(num2 >= num3), we conclude that num2 is the largest of the three numbers. In case the test num1 < num2
fails, i.e. num2 <= num1, we compare num1 with num3. If num1 < num3, we have found that num3 is the largest
of the three numbers. However, in the other case (num1 >= num3), we conclude that num1 is the largest of the
three numbers. We use this analysis to write function max3(num1, num2, num3), which finds the maximum of
three numbers num1, num2, and num3. Subsequently, the function max3() is used in Program 10.11, to accept
three numbers from a user and find their maximum.
01 def max3(num1, num2, num3):
02 '''
Conditional Statements 267

