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
Kung815
V2EX  ›  Python

请问这个计算 1 到 100 之和的代码为什么会报错?

  •  
  •   Kung815 · 2017-07-25 15:20:26 +08:00 · 1669 次点击
    这是一个创建于 2459 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如图 http://wx2.sinaimg.cn/mw690/7f924972gy1fhw5ilojn4j20r8086aa2.jpg

    如果将 print 缩进, 就会返回一系列和, 所以请问如何使其只返回 5050。

    2 条回复    2017-07-27 11:34:20 +08:00
    bubuyu
        1
    bubuyu  
       2017-07-25 15:33:44 +08:00
    for 那里不该有 number()
    sum=sum+x 下面直接按回车,print 前面 不该有...
    Marmot
        2
    Marmot  
       2017-07-27 11:34:20 +08:00
    确实有点问题,ipyhton 就可以,有点怪。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5513 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 03:20 · PVG 11:20 · LAX 20:20 · JFK 23:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.