Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__next__ 方法下的 for in #105

Closed
10203901427 opened this issue Nov 24, 2020 · 1 comment
Closed

__next__ 方法下的 for in #105

10203901427 opened this issue Nov 24, 2020 · 1 comment

Comments

@10203901427
Copy link

55fb6b5e135738a60764e0a15ec1bae
老师,我运行了以后就成了找奇数,好像for in没起作用,是for in 在__next__方法下用不了吗?还是哪里错了呀

@neolee neolee changed the title __next__方法下的for in __next__ 方法下的 for in Nov 25, 2020
@neolee
Copy link
Owner

neolee commented Nov 25, 2020

__next__() 方法里的逻辑写错了,你可以看看我在这个问题里的回答 #101 ,按照里面的思路再想想。

p.s. 仔细看你目前的代码,你目前的逻辑是:对 2~b 之间的整数 a 循环执行,用 a 去除 self.base,除尽了就 break(然后函数就结束了,返回一个 None),除不尽就返回 self.base,这样的话,无论除不除得尽,你的循环都只会执行一次就退出了,这肯定是不对的吧?所以我建议把“判断 n 是否素数”这个功能单独写成一个函数,然后按照我上面给你的 #101 问题里提示的思路去做。

@neolee neolee closed this as completed Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants