Page 438 - Computer Science Class 11 With Functions
P. 438

'2': 'two',

                  '3': 'three',
                  '4': 'four',
                  '5': 'five',

                  '6': 'six',
                  '7': 'seven',
                  '8': 'eight',
                  '9': 'nine'
                  }


                  if digit in digitWords:
                      return digitWords[digit]

                  else:
                      return "Invalid input: Not a digit"

             digit = input("Enter a numeric digit (0-9): ")
             result = digitToText(digit)

             print(result)
        Program 25

        Write a program that reads the colour of traffic light as user input in the form of a string and displays the output as
        per the table given below:


                                      Colour                          Output
                             Red                       STOP
                             Yellow                    Get ready
                             Green                     GO
                             Any other colour          You have not entered the correct colour

        Ans. def trafficLight(color):
                 '''
                 Objective : To display output according to traffic light color

                 Input Parameter : color - string
                 Return Value : None
                 '''
                 # Check the color and display the corresponding output

                 if color.lower() == "red":
                     print("STOP")
                 elif color.lower() == "yellow":
                     print("Get ready")
                 elif color.lower() == "green":
                     print("GO")


         436   Touchpad Computer Science-XI
   433   434   435   436   437   438   439   440   441   442   443