我试图编写的程序有什么问题

时间:2016-07-04 20:45:43

标签: python

#This is a program which illustrates a chaotic behavior.


def main():
    print("This is a program which illustrates a chaotic behavior")
    x = eval(input("Enter a value between 0 and 1: "))
    for i in range(10):
    x = 3.9 * x * (1 - x)
    print(x)

main()的

我正在阅读这本书和#34; Python编程,John Zelle对计算机科学的介绍"我正在尝试复制粘贴这个简单的程序。 我正在使用Geany IDE,在编写上面的代码之后我正在尝试编译它但是我收到以下错误:

Sorry: IndentationError: expected an indented block (chaos.py, line 5)

3 个答案:

答案 0 :(得分:1)

错误消息告诉您完全错误:当您有一个循环(或其他代码块)时,您需要缩进其内容。否则,解释器无法知道循环体是什么或不是循环体的一部分。

def main():
    print("This is a program which illustrates a chaotic behavior")
    x = eval(input("Enter a value between 0 and 1: "))
    for i in range(10):
        x = 3.9 * x * (1 - x) # INDENT THIS
        print(x)              # AND THIS

答案 1 :(得分:1)

必须是

for i in range(10):
    x = 3.9 * x * (1-x)
    print x

Python使用缩进来对语句进行分组,例如在循环体中。

答案 2 :(得分:0)

缩进行

x = 3.9 * x * (1 - x)
print(x)
相关问题