Page 291 - Computer Science V2.0 Class 11
P. 291

2.  Hamza wants to create a program that asks a user whether he has seen the moon or not. If the user replies with yes,
                      Hamza wants to display the message 'EID MUBARAK'.
                  Ans. answer = input('Have you seen the moon? (yes/no) ')
                      if answer == 'yes':
                          print('EID MUBARAK')
                    3.  Jacky has just finished his Class 9 final exams. He knows that his teachers will soon share marks scored by all students in his
                      class. Thereafter, the percentage will be calculated and then each student will be given grades according to the table given
                      below:

                                               Percentage of Marks             Grade
                                            >=95                             Outstanding
                                            >=90 and <95                         A
                                            >=75 and <90                         B
                                            >=60 and <75                         C
                                            <60                                  D
                      He wants to write a program in Python for his friends which allows one to enter marks scored in all five subjects - English,
                      Hindi, Maths, Science and Social Science. The program will then calculate the percentage, assuming the maximum mark in
                      each subject to be 100. Thereafter, the program should display the Grade achieved by the student. Help Jacky to complete
                      his task.

                  Ans. def grade(marksEnglish, marksHindi, marksMaths, marksSc, marksSSc):
                          '''
                          Objective: To find and display grades
                          Input Parameters:marks in five subjects - int values
                          Return Value: grade
                          '''
                           if marksEnglish>=33 and marksHindi>=33 and marksMaths>=33 and marksSc>=33 and
                           marksSSc>=33:
                              #Eligible to be promoted
                              totalMarks = marksEnglish + marksHindi + marksMaths + marksSc + marksSSc
                              percent = (totalMarks/500)*100

                              if percent>=95:
                                  grade =  'Outstanding'
                              elif percent >= 90 and percent<95:
                                  grade = 'A'
                              elif percent >=75 and percent<90:
                                  grade = 'B'
                              elif percent>= 60 and percent<75:
                                  grade = 'C'
                              elif percent < 60:
                                  grade = 'D'
                          else:
                              # Not eligible to be promoted
                              grade = 'Failed'
                          return grade

                      def main():

                                                                                               Conditional Statements  277
   286   287   288   289   290   291   292   293   294   295   296