Page 257 - CTS - CSA TP - Volume 2
P. 257

COMPUTER SOFTWARE APPLICATION - CITS




               print(“You scored grade B+...”)
           elif marks > 40 and marks <= 60:

               # If the condition is true, we will enter this block
               print(“You scored grade B...”)
           elif marks > 30 and marks <= 40:
               # If the condition is true, we will enter this block

               print(“You scored grade C...”)
           else:
               # If none of the above conditions are true, we will enter this block
               print(“Sorry, you have failed.”)
           Explanation:
           •  marks = int(input(“Enter the marks? “)): Takes user input for marks and converts it to an integer.

           •  The code uses if-elif-else statements to check different conditions based on the value of ‘marks’.
           •  Conditions are checked in the order they appear, and the first true condition’s block is executed.
           •  If marks are greater than 85 and less than or equal to 100, it prints “Congrats! You scored grade A...”
           •  If not, it moves to the next elif and checks if marks are greater than 60 and less than or equal to 85.

           •  The process continues for the other elif conditions.
           •  If none of the conditions are true, the else block is executed, and it prints “Sorry, you have failed.”
           Output:





























           TASK 5: Match Case
           Code:

           num=int(input(“Enter the Number: “))
           defdescribe_number(num):
               matchnum:
                   case 0:
                       return “Zero”



                                                           242
                              CITS : IT & ITES - Computer Software Application - Exercise 125
   252   253   254   255   256   257   258   259   260   261   262