Python codes for extra credit