Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 146 - CodePilot V5.0 C6
P. 146

    SOME MORE PROGRAMS

                       Program 7     To multiply two numbers entered by the user.

                           Program7.py
                        File  Edit  Format   Run   Options   Window    Help

                        num1 = int(input("Enter the first number: "))
                        num2 = int(input("Enter the second number: "))
                        print("The product of the two numbers is:", num1 * num2)

                           Output

                        Enter the first number: 23
                        Enter the second number: 17
                        The product of the two numbers is: 391

                       Program 8     To calculate the perimeter of a rectangle.

                           Program8.py

                        File  Edit  Format   Run   Options   Window    Help

                        length = float(input("Enter the length of the rectangle: "))
                        width = float(input("Enter the width of the rectangle: "))
                        perimeter = 2 * (length + width)
                        print("The perimeter of the rectangle is:", perimeter)

                           Output
                        Enter the length of the rectangle: 40
                        Enter the width of the rectangle: 20
                        The perimeter of the rectangle is: 120.0

                       Program 9 To calculate the average of three numbers.

                           Program9.py
                        File  Edit  Format   Run   Options   Window    Help

                        num1 = float(input("Enter the first number: "))
                        num2 = float(input("Enter the second number: "))
                        num3 = float(input("Enter the third number: "))
                        average = (num1 + num2 + num3) / 3
                        print("The average of the three numbers is:", average)

                       144
                            CodePilot (V5.0)-VI

         5

| 141 142 143 144 145 146 147 148 149 150 151 |