Page 356 - Information_Practice_Fliipbook_Class11
P. 356

Program 29: Write a program that accepts the length in inches and prints the length in feet.


        Ans. '''
             Objective: To convert the length in inches to feet

             Input: length in inches

             Output: length in feet
             '''

             inches = float(input("Enter length in inches: "))
             feet = inches / 12.0

             print(f"Length in feet is: {feet} feet")
         Program 30: 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. '''

             Objective: To display output according to traffic light color
             Input: color

             Output: output according to color

             '''
             color = input("Enter the color of the traffic light: ")

             if color.lower() == "red":
                print("STOP")

             elif color.lower() == "yellow":
                print("Get ready")

             elif color.lower() == "green":
                print("GO")

             else:
                print("You have not entered the correct color")

         Program 31: Write a program that takes a number num as an input and prints the sum of natural numbers until the
         limit defined by num.

        Ans. '''

             Objective: To calculate sum of first N natural numbers

             Input: num
          342  Touchpad Informatics Practices-XI
   351   352   353   354   355   356   357   358   359   360   361