Solved problem17 in python3