我如何在python中的0和所有输入之间保持数字

发布于 2025-02-07 15:41:26 字数 1490 浏览 0 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟凡古楼 2025-02-14 15:41:26

如果我正确解释您的问题,您只需要设计一个非常简单的列表理解程序即可。

不需要在零和n之间获得所有事物的平方根。你是刻空的吗?

这是我的解决方案:

def nbDig(n,d):
    int_list = str([str(x*x) for x in range(0,n+1)]).count(str(d))
    return int_list

我可以像这样测试:

nbDig(12,1)

返回7。

编辑:我没有意识到呼叫。重新定位是完全不必要的。感谢您的反馈!

If I am interpreting your question correctly, you simply need to devise a very simple list comprehension program.

Getting the square root of everything between zero and n is not necessary. Did you mean square?

Here's my solution:

def nbDig(n,d):
    int_list = str([str(x*x) for x in range(0,n+1)]).count(str(d))
    return int_list

I can test it like so:

nbDig(12,1)

This returns 7.

EDIT: I didn't realize calling .replace was totally unnecessary. Thanks for the feedback!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文