调试无效的语法错误iPython [英] debugging invalid syntax error iPython
问题描述
我迎接以下语法错误之后我执行该程序从感谢此篇thkang
I am greeted with the following syntax error after I execute the program thanks thkang from this post
You entered: ./#
Expanded to: ./#
=================
File "./largestoddxyz.py", line 43
else: #x and z are even
^
SyntaxError: invalid syntax
以下是代码:
我不熟悉使用Python并试图解决这个问题,但不幸的是,我无法解决。希望这里有人能帮助我。
Here is the code:
I am new to using Python and tried to fix the issue, but unfortunately, I wasn't able to. Hopefully someone here can help me.
#!/usr/bin/env python
# This program exmamines variables x, y, and z
# and prints the largest odd number among them
import sys
x,y,z = map(int,sys.argv[1:4])
if x%2 != 0:
if y%2 != 0:
if z%2 != 0:
if x > y and x > z: #x is the biggest odd
print 'x is the biggest odd ' and x
elif y > z and y > x: #y is the biggest odd
print 'y is the biggest odd ' and y
elif z > x and z > y: #z is the biggest odd
print 'z is the biggest odd ' and z
else: #z is even
if x > y: #x is the biggest odd
print 'x is the biggest odd ' and x
else: #y is the biggest odd
print 'y is the biggest odd ' and y
else: #y is even
if z%2 != 0: #z is odd
if x > z: #x is the biggest odd
print 'x is the biggest odd ' and x
else: #z is the biggest odd
print 'z is the biggest odd ' and z
else: #y,z are even and x is the biggest odd
print 'x is the biggest odd ' and x
else: #x is even
if y%2 != 0 and z%2 != 0: #y,z is odd
if y > z: #y is the biggest odd
print 'y is the biggest odd ' and y
else: #z is the biggest odd
print 'z is the biggest odd ' and z
else: #x and y are even
if z%2 != 0: #z is the biggest odd
print 'z is the biggest odd ' and z
else: #x and z are even
if y%2 != 0: #y is odd
if z%2 = 0: #z is even
print 'y is the biggest odd ' and y
print 'finished'
推荐答案
缩进是错误的;注意
else: #x and y are even
if z%2 != 0: #z is the biggest odd
print 'z is the biggest odd ' and z
else: #x and z are even
你想缩进第二个 else
以及它下面的所有内容。您可能需要运行 pep8
来验证一切都井井有条,即你使用正确的间距,不要混合标签和空格字符。
You want to indent the second else
and everything below it. You may want to run pep8
to verify that everything is in order, i.e. that you're using correct spacing and don't mix tabs and space characters.
此外,在行
if z%2 = 0: #z is even
您想要比较 ==
,而不是作业 =
。
you want the comparison ==
, not the assignment =
.
这篇关于调试无效的语法错误iPython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!