Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 149 - 2633 Trackpad Pro V5.1 Class 7
P. 149

    For example:
                         IDLE Shell 3.10.5

                      File  Edit  Format   Run    Options  Window     Help

                      >>> a=10
                      >>> b=0
                      >>> c=a/b                                                      Invalid Logic
                      Traceback (most recent call last):
                          File "<pyshell#5>", line 1, in <module>
                           c=a/b
                          ZeroDivisionError: division by zero

                               SOME MORE PROGRAMS

                     1.  Write a program to take distance in Kilometres and convert it into Meters.

                         Program1.py
                      File  Edit  Format   Run    Options   Window    Help

                      #Take distance in kilometer from the user
                      km=float(input("Enter distance in kilometres "))

                      m=km*1000
                      print("Distance in meters is ", m)

                         Output

                      Enter distance in kilometres 10
                      Distance in meters is  10000.0

                     2.   Write a program to take the length and width of a rectangle as input and calculate its area.

                         Program1.py
                      File  Edit  Format   Run    Options   Window    Help

                      #Program to calculate the area
                      l=int(input("Enter the Length "))

                      w=int(input("Enter the Width "))
                      area= l * w
                      print("Area of the Rectangle is : ", area)

                                                                                        Tokens and Data Types in Python  147

| 144 145 146 147 148 149 150 151 152 153 154 |