Page 137 - 2622_Delhi Police Public School_C-8
P. 137

Program 11: To perform various string operations

                     Program11.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



                 On running the above program, you will get the following output:
                     Output

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


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

                     Program12.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)



                 On running the above program, you will get the following output:

                     Output
                  Input the sides of the triangle:
                  A: 2.3
                  B: 5.3
                  C: 9.5
                  Scalene triangle





                                                                                   Functions and String  in Python  135
   132   133   134   135   136   137   138   139   140   141   142