Page 109 - KEC Khaitan C8 Flipbook
P. 109

You will get the following output:

                     Output
                  Calculate Area for: Rectangle, Square, or Circle
                  Enter the name of the shape whose area you want to find: Circle
                  Enter the radius of the circle: 4.5
                  The area of the circle is:  63.585



                 Program 17: To access string characters
                     Program17.py
                  File  Edit  Format   Run    Options   Window    Help

                  #Accessing string characters in Python
                  str = 'Orange Education'
                  print('str = ', str)
                  print('str[0] = ', str[0])                 #First character
                  print('str[-1] = ', str[-1])               #Last character



                 You will get the following output:

                     Output

                  str =  Orange Education
                  str[0] =  O
                  str[-1] =  n




                 Program 18: To check whether the side of the triangle given by the user form a scalene, isosceles or
                 equilateral triangle

                     Program18.py
                  File  Edit  Format   Run    Options   Window    Help


                  #Program to check if a triangle is Equilateral, Isosceles or Scalene

                  def triangle(A,B,C):
                      if (A == B == C):
                          print('Equilateral triangle')
                      elif ((A == B) or (B == C) or (A == C)):
                          print('Isosceles triangle')
                      else:
                          print('Scalene triangle')
                  print('Input the sides of the triangle: ')
                  A1 = float(input('A: '))
                  B1 = float(input('B: '))
                  C1 = float(input('C: '))
                  triangle(A1,B1,C1)






                                                                                   Functions, String and List in Python  107
   104   105   106   107   108   109   110   111   112   113   114