Updated Problem 1 Python solution