[问题] 新手发问

楼主: xup6yvu06 (JOY)   2020-05-08 12:56:34
大家好,
目前看彭彭老师的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
请问我改如何修改让程式继续跑下去呢?
谢谢
作者: annheilong (方格子)   2020-05-08 13:25:00
你是不是用到 Python 2 了? Python 3 才会正常喔
作者: kenduest (小州)   2020-05-08 13:28:00
正在用 python2 ? 请务必改用 python3 来学习
楼主: xup6yvu06 (JOY)   2020-05-08 13:33:00
我下载的是3.8
作者: cuteSquirrel (松鼠)   2020-05-08 13:45:00
用 python 3吧 官方的维护主力在3.X 以后的版本
作者: jezi1878 (小天使)   2020-05-08 13:48:00
你是不是用苹果电脑,它本身内建2.7版本,就算灌了3.6版本。设定值没设好,还是用2.7在跑
楼主: xup6yvu06 (JOY)   2020-05-08 13:54:00
对,我刚刚检查了,terminal显示的是python2,我以为我安装好了,感谢大家提点
作者: MAGICXX (逢甲阿法)   2020-05-08 18:01:00
我还是习惯用python2.7...Y
作者: salmon12706 (Ellen)   2020-06-29 16:25:00
工研院人工智能课程推荐https://reurl.cc/4RDRaK

Links booklink

Contact Us: admin [ a t ] ucptt.com