added and completed ex39.py