Check whether the Average Character of the String is present or not | Python 3 program to check if the average character is present in the string or not ; Checks if the character is present ; Get the length of string ; Iterate from i = 0 to the length of the string to check if the character is present in the string ; Finds the average character of the string ; Calculate the sum of ASCII values of each character ; Calculate average of ascii values ; Convert the ASCII value to character and return it ; Driver code ; Get the average character ; Check if the average character is present in string or not
from math import floor NEW_LINE def check_char ( st , ch ) : NEW_LINE INDENT l = len ( st ) NEW_LINE for i in range ( l ) : NEW_LINE INDENT if ( st [ i ] == ch ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def find_avg ( st ) : NEW_LINE INDENT sm = 0 NEW_LINE l = len ( st ) NEW_LINE for i in range ( l ) : NEW_LINE INDENT ch = st [ i ] NEW_LINE sm = sm + ord ( ch ) NEW_LINE DEDENT avg = int ( floor ( sm / l ) ) NEW_LINE return ( chr ( avg ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT st = " ag23sdfa " NEW_LINE ch = find_avg ( st ) NEW_LINE print ( ch ) NEW_LINE if ( check_char ( st , ch ) == True ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT