【发布时间】:2011-10-30 20:32:29
【问题描述】:
我正在尝试创建一个简单的程序来将 Collatz 猜想的语句应用于用户可以输入的整数,我有:
def collatz(n):
print n,
if n % 2 ==0:
n = n / 2
elif n == 0:
Print "Collatz Conjecture true for" , 'n'
else:
n = n *3 + 1
input("\n\nInsert a positive integer:")
def collatz(n)
但是它说该行中有语法错误:
Print "Collatz Conjecture true for" , 'n'
我看不出这行有什么错误。
另外,我还没有能够测试它,这看起来是否可以正常工作?
【问题讨论】:
-
修复语法错误后,您需要添加loop。
-
您还需要在某处定义
n,最好是input()的结果(无论如何应该是raw_input(),因为您显然使用的是Python 2)。你至少读过一点 Python 教程吗?