# Rectangles.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-04-21 File created. # 2022-12-27 Converted to Python 3. # In python classes data attributes (data fields) are created # with assignment statements like # self.data_field_name = ... # The word 'self' is commonly used to refer to 'this' instance object. # The data attributes of the Rectangle class are created when # the initialize_rectangle() method is called. class Rectangle : def initialize_rectangle( self, given_rectangle_width, given_rectangle_height, given_filling_character ) : self.rectangle_width = given_rectangle_width self.rectangle_height = given_rectangle_height self.filling_character = given_filling_character def print_rectangle( self ) : # We construct a string that contains the # characters that are supposed to go on each row. In the following # statement operator * concatenates the string self.filling_character # as many times as is the value of self.rectangle_width. characters_on_each_row = self.rectangle_width * self.filling_character for number_of_rows_printed in range( self.rectangle_height ) : print( "\n " + characters_on_each_row, end="" ) print( "" ) # an empty line # the main program first_rectangle = Rectangle() first_rectangle.initialize_rectangle( 7, 4, 'Z' ) first_rectangle.print_rectangle() second_rectangle = Rectangle() second_rectangle.initialize_rectangle( 12, 3, 'X' ) second_rectangle.print_rectangle()