python
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
def colorize_code(code):
lexer = PythonLexer()
formatter = HtmlFormatter()
return highlight(code, lexer, formatter)
if __name__ == "__main__":
code = '''
def greet(name):
print("Hello, " + name + "!")
greet("World")
'''
highlighted_code = colorize_code(code)
print(highlighted_code)
pip install pygments