Page 53 - Code & Click - 7
P. 53

Mind Stretching

             1. Identify and underline the errors in the code given below. Also, write the correct code.
                                                                                                      Logical Thinking
                 # Program to accept two numbers. If the numbers are equal, display
                 their product otherwise, display the remainder when the larger
                 number is divided by the smaller number.
                 Num1 = input(“Enter first number : ”)
                 Num2 = input(“Enter second number : ”
                 Num2 = int(Num2)
                 Num1 = int(Num1)
                 If Num1 = Num2:
                    print(Num1 * Num2)
                 Else if (Num1 > Num2):
                     print(“Num1 / Num2”)
                 else:
                     print(Num2 % Num1)
             2. Write the output of the following code segments in Python:                        Computational Skills
                 X = 56
                 if (X > 100):
                     print(“X is greater than 100”)
                 else:
                     print(“X is smaller than 100”)

                 if (X > 50):
                     print(“but X is greater than 50”)
                 else:
                     print(“and X is smaller than 50 also”)


                                                                                                  Computational Skills
             Lab Work

             Write the following programs in Python:
               (a)  Program to accept an alphabet from the user and display whether it is a vowel or consonant.
               (b)  Program to accept a number from the user and display whether it is a multiple of 7 or not.
               (c)  Program to accept three numbers from the user. Display the product of the numbers with the
                    message whether the product is even or odd.
               (d)  Program to accept the number of units of electricity consumed by a user in a month and calculate
                    and display his bill. The criteria used for the calculation of the bill are as follows:
                                     Number of units                      Cost per unit
                                        Upto 200                               ` 0

                                     From 201 to 300                           ` 5
                                     From 301 to 500                           ` 6
                                      501 and above                            ` 7


                                                                                                                 51
   48   49   50   51   52   53   54   55   56   57   58