在pep8没有返回任何东西之后调试python,但我仍然有一个语法错误



在收到phihag对我上一篇文章的必要帮助后,我注意到我并没有得到所有偶数的结果。但是,我一直在第47行收到语法错误,else语法无效。

else:  # x, y, and z are even

有什么问题吗?

#!/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 ', x
            elif y > z and y > x:  # y is the biggest odd
                print 'y is the biggest odd ', y
            elif z > x and z > y:  # z is the biggest odd
                print 'z is the biggest odd ', z
        else:  # z is even
            if x > y:  # x is the biggest odd
                print 'x is the biggest odd ', x
            else:  # y is the biggest odd
                print 'y is the biggest odd ', 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 ', x
            else:  # z is the biggest odd
                print 'z is the biggest odd ', z
        else:  # y,z are even and x is the biggest odd
            print 'x is the biggest odd ', 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 ', y
        else:  # z is the biggest odd
            print 'z is the biggest odd ', z
    else:  # x and y are even
        if z % 2 != 0:  # z is the biggest odd
            print 'z is the biggest odd ', 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 ', y
    else:  # x, y, and z are even
        if z % 2 == 0:
            print 'x, y, and z are even.'
print 'finished'

在相同的缩进级别有两个else,一个接一个,这是无效的。你的意思是其中一个是elif吗?

最新更新