作者xup6yvu06 (JOY)
看板Python
标题[问题] 新手发问
时间Fri May 8 12:56:34 2020
大家好,
目前看彭彭老师的youtube videos学习python,目前学习到if判断式
我跟着老师打的程式出现了错误无法正确跑完,烦请大家教导我哪里出错,谢谢
以下为程式码
x=int(input('enter a number: '))
y=int(input('enter a number: '))
op=input('enter an operator: +, -, *, /: ')
if op=='+':
print(x+y)
elif op=='-':
print(x-y)
elif op=='*':
print(x*y)
elif op=='/':
print(x/y)
else:
print('not an operator')
输入完两个数值及运算子後,出现以下讯息,
enter a number: 6
enter a number: 8
enter an operator: +, -, *, /: /
Traceback (most recent call last):
File "condition2.py", line 3, in <module>
op=input('enter an operator: +, -, *, /: ')
File "<string>", line 1
/
^
SyntaxError: unexpected EOF while parsing
请问我改如何修改让程式继续跑下去呢?
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 47.184.77.89 (美国)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1588913796.A.A72.html
1F:推 annheilong: 你是不是用到 Python 2 了? Python 3 才会正常喔 05/08 13:25
2F:推 kenduest: 正在用 python2 ? 请务必改用 python3 来学习 05/08 13:28
3F:→ xup6yvu06: 我下载的是3.8 05/08 13:33
4F:推 cuteSquirrel: 用 python 3吧 官方的维护主力在3.X 以後的版本 05/08 13:45
5F:推 jezi1878: 你是不是用苹果电脑,它本身内建2.7版本,就算灌了3.6 05/08 13:48
6F:→ jezi1878: 版本。设定值没设好,还是用2.7在跑 05/08 13:48
7F:→ xup6yvu06: 对,我刚刚检查了,terminal显示的是python2,我以为我 05/08 13:54
8F:→ xup6yvu06: 安装好了,感谢大家提点 05/08 13:54
9F:推 MAGICXX: 我还是习惯用python2.7...Y 05/08 18:01