【问题标题】:For loop fails, but code appears to be correct [closed]For循环失败,但代码似乎是正确的[关闭]
【发布时间】:2019-03-07 23:24:21
【问题描述】:

我的代码看起来不错,但我的 for 循环中出现语法错误。有谁知道为什么会这样?我在下面包含了我的代码:

def printLine(numberOfDots):
    dots = 0
    for x in range numberOfDots:
        dots += 1
    printDots = print("." * dots)
    return printDots

printLine(20)

【问题讨论】:

  • 将您的代码发布为文本,而不是图像(绝对不是图像链接)。
  • 不知何故,链接的图像看起来好像被编辑为比普通屏幕截图更难阅读......
  • 我无法让 Python 解释器运行您发布的图像。

标签: python-2.7 for-loop


【解决方案1】:

range 是一个函数,所以你应该使用range(numberOfDots) 而不是range numberOfDots。

【讨论】:

  • 还是不行
  • 既然你从来没有解释过它应该做什么,恐怕我帮不上什么忙。
猜你喜欢
  • 1970-01-01
  • 2013-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-12
  • 1970-01-01
  • 2021-01-26
  • 1970-01-01
相关资源
最近更新 更多