Python While Loop, the and (&) operator is not working

╄→гoц情女王★ 提交于 2019-12-01 17:46:11

You should be using the keyword and instead of the bitwise and operator &:

while (v % d != 0) and (u % d != 0): 

This is also the same:

while (v % d) and (u % d): 

Note that & and and will give the same result in the first case, but not in the second.

Your problem though is that you want to use or instead of and. Also your algorithm is highly inefficient. There are better ways to calculate the GCD.

Use the and keyword. & is a bitwise and operator.

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