Page 340 - Information_Practice_Fliipbook_Class11
P. 340

Practical







                                                       Solved

         Program 1: Write a program that takes a year as an input from the user and checks whether the given year is a leap
         year or not.


        Ans. '''
             Objective: To check whether the given year is a leap year or not

             Input: year – numeric value
             Output: appropriate message

             '''


             year = int(input("Enter a year: "))


             if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):

                  print(f"{year} is a leap year.")
             else:

                  print(f"{year} is not a leap year.")
         Program 2: Write a program that accepts a digit as an input from the user. If the digit is a positive number (1-9), then
         display it in words; otherwise, display the message, "Error: A positive digit is expected and less than 10".

        Ans. '''

             Objective: To display digits in words

             Input: digit – numeric value
             Output: appropriate message

             '''


             digit = int(input("Enter a digit: "))
             if digit >= 0:

                   digitWords  = ["Zero",  "One",  "Two",  "Three",  "Four",  "Five",  "Six",
                    "Seven", "Eight", "Nine"]

                  print(f" digit {digit} in words is: { digitWords [digit]}")
             else:

                  print("Error: A positive digit is expected or less than 10.")



          326  Touchpad Informatics Practices-XI
   335   336   337   338   339   340   341   342   343   344   345