# Uplow.py (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-04-19 File created. # 2022-12-27 Converted to Python 3. # This program demonstrates, among other things, the use of bit operator &. # With built-in function ord() it is possible to find out the integer # character code of the character in a single-character string. # With built-in function chr() it is possible to convert an # integer code to a single-character (unicode) string. def convert_string_uppercase( given_string ) : character_index = 0 modified_string = "" while character_index < len( given_string ) : if given_string[ character_index ] >= "a" and \ given_string[ character_index ] <= "z" : modified_string += \ chr( ord( given_string[ character_index ] ) & 0xDF ) else : modified_string += given_string[ character_index ] character_index += 1 return modified_string # The main program. test_string = "Guido van Rossum invented Python." ; print( "\n String before conversion: " + test_string, end="" ) uppercase_string = convert_string_uppercase( test_string ) print( "\n String after conversion: " + uppercase_string, end="" ) print( "\n Better conversion: " + test_string.upper() )