problem47.py corrected