V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
s04
V2EX  ›  Python

#Checkio 陷入僵局,求大佬解答

  •  
  •   s04 · 2018-06-17 14:09:48 +08:00 · 2943 次点击
    这是一个创建于 2111 天前的主题,其中的信息可能已经有所发展或是发生改变。
    def checkio(words: str) -> bool:
    split_words = words.split()
    count = 0
    for w in split_words:
    if w.isalpha():
    count += 1
    while count == 3:
    return True
    break
    elif w.isdigit():
    count = 0
    if count == 3:
    return True


    checkio('one two 3 four five six 7 eight 9 ten eleven 12')

    本人千方百计试图将 for 循环里边的 count 变为 3 后返回 true 后解决题目,但不管如何返回的都是 False.
    除此之外,为什么 for 循环里边 w 是一个字符串而不是这个列表的索引值。
    15 条回复    2018-06-17 19:33:00 +08:00
    s04
        1
    s04  
    OP
       2018-06-17 14:11:47 +08:00
    lijsh
        2
    lijsh  
       2018-06-17 15:23:14 +08:00
    好久没玩了,精神上支持一下。

    不是有别人的解答可以参考的吗
    hustfox
        3
    hustfox  
       2018-06-17 15:23:47 +08:00 via Android
    git 打开 404。要索引可以用:for i,w in enumerate(split_words)呀
    s04
        4
    s04  
    OP
       2018-06-17 16:16:04 +08:00
    @lijsh 没做完,看不到
    s04
        5
    s04  
    OP
       2018-06-17 16:17:30 +08:00
    @hustfox 代码就 1L 主题那部分,2L 是一样的内容
    lijsh
        6
    lijsh  
       2018-06-17 16:18:46 +08:00
    @s04 #4 是哪个问题,我看看我做过了没
    Sanko
        7
    Sanko  
       2018-06-17 16:45:27 +08:00 via Android
    陷入江局
    hustfox
        8
    hustfox  
       2018-06-17 17:10:32 +08:00 via Android
    @s04 额,Python 不是根据缩进来的么?贴出来的完全没缩进呀
    s04
        9
    s04  
    OP
       2018-06-17 17:25:01 +08:00
    Kagari
        10
    Kagari  
       2018-06-17 18:16:20 +08:00
    s04
        11
    s04  
    OP
       2018-06-17 18:27:03 +08:00
    s04
        12
    s04  
    OP
       2018-06-17 18:34:46 +08:00
    @Kagari 应该是我没有变成公开的导致不能直接打开吧
    hustfox
        13
    hustfox  
       2018-06-17 19:19:33 +08:00   ❤️ 1
    我试了是返回 True 的呀。另外,return True 后面 break 就没用了;最后的判断 if count == 3 也没用吧
    s04
        14
    s04  
    OP
       2018-06-17 19:30:32 +08:00
    @hustfox 刚刚我吧 if count ==3 改成 !=3 就行了。我被 IDE ( pycharm )的返回结果:进程完成,退出码为 0 给误导了 QAQ。
    s04
        15
    s04  
    OP
       2018-06-17 19:33:00 +08:00
    @Sanko 你是想上枪毙名单吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3230 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:18 · PVG 22:18 · LAX 07:18 · JFK 10:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.