How to draw a checkered flag to the Python screen?

可紊 提交于 2019-12-04 22:10:55

If you want to return two values, you must combine them in some way. If you do this:

return row
return col

the program will return the row and then exit the function, because that's what return does. Nothing after the first return will ever be executed. Try this instead:

return row, col

The returned value will be a tuple, which is exactly what you need to carry out row, col = findGrid(x) as appears in your main(). Instead of evaluating to a single int, findGrid(x) will instead evaluate to a tuple containing two ints, and Python can iterate over that tuple to place each value into the specified variables row and col.

The error messages generated by the Python interpreter are usually pretty informative. In this case, when it says int object is not iterable, you can bet that it tried to iterate over an int and understandably failed. All you have to do then is deduce where the erroneous statement in question is looking for an iterable, find what produces the problematic expression (findGrid(x)), and inspect whether it returns an int or an iterable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!