Convert print statement with print function. Fix bugs