Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 100 - 2611_SmartGPT Pro V(5.0) C-8
P. 100

    capitalize(): The capitalize() function returns a string with the first character in capital  and
                         the rest in lowercase. The syntax of using capitalize() function is:

                         string_name.capitalize()
                      Program 9: To use various string built-in functions

                          Program9.py                                               Output
                        File  Edit  Format  Run   Options   Window   Help        5
                                                                                 hello
                        str = 'Hello'
                        print(len(str))                                          HELLO
                        print('Hello'.lower())                                   Hello
                        print('hello'.upper())
                        print('hello'.capitalize())

                                               1.  What is a string?
                              uiz    Bee          _____________________________________________________________

                                               2.  What are escape sequences?
                                                  _____________________________________________________________

                                SOME MORE PROGRAMS

                      Program 10: To calculate the area of different shapes

                          Program10.py
                       File  Edit  Format   Run   Options  Window    Help

                       def calculate_area(name):
                           name = name.lower()
                           if(name == 'rectangle'):
                               l = float(input('Enter the length of the rectangle: '))
                               b = float (input('Enter the breadth of the rectangle: '))
                               rect_area = 1 * b
                               print('The area of the rectangle is: ', rect_area)
                           elif(name == 'square'):
                               s = float(input('Enter the side of the square: '))
                               sqr_area = s * s
                               print('The area of the square is:', sqr_area)
                           elif (name == 'circle'):
                               pi = 3.14
                               r = float(input('Enter the radius of the circle: '))
                               circle_area = pi * r**2
                               print('The area of the circle is: ', circle_area)
                           else:
                               print('sorry! This shape is not available')
                       print('Calculate Area for: Rectangle, Square, or Circle')
                       shape_name = input('Enter the name of the shape whose area you want to find: ')
                       calculate_area(shape_name)

                       98   Computer Science (V5.0)-VIII

| 95 96 97 98 99 100 101 102 103 104 105 |