python的语法问题

CopyReg 2011-04-16 04:55:02
#!/usr/bin/env python
# Filename: if.py

number=23
guess=int(input(('Enter an integer : '))

if guess==number:
print ('Congratulations, you guessed it.') # New block starts here
print ("(but you do not win any prizes!)") # New block ends here
elif guess<number:
print ('No, it is a little higher than that') # Another block
# You can do whatever you want in a block ...
else:
print ('No, it is a little lower than that')
# you must have guess > number to reach here

print ('Done')
# This last statement is always executed, after the if statement is executed



这些代码我是在http://woodpecker.org.cn/abyteofpython_cn/chinese/ch06s02.html复制下来的
我把raw_input替换成了input(我的python是3.1.2的)

可是我运行的时候出现了错误
if guess==number:
^
SyntaxError: invalid syntax

请问错误出在哪里呢?那个教程好像是2.X的,难道因为我用的是3.X所以出错了吗?
...全文
85 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
CopyReg 2011-04-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 josephwuxiaameng 的回复:]

大哥你int的括号没对齐!
[/Quote]

真的少个哦
josephwuxiaameng 2011-04-16
  • 打赏
  • 举报
回复
大哥你int的括号没对齐!
angel_su 2011-04-16
  • 打赏
  • 举报
回复
没细看,应该是多了一个'(',guess=int(input('Enter an integer : '))
angel_su 2011-04-16
  • 打赏
  • 举报
回复
guess=int(input(('Enter an integer : '))有问题,少一个')'吧,所以后面语句看起来没问题也会报语法错误...

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧