【问题标题】:debugging ipython after pep8 returns nothing but I still have a syntax error在 pep8 之后调试 ipython 什么也没返回,但我仍然有语法错误
【发布时间】:2013-03-31 23:44:18
【问题描述】:

在我的previous post 收到来自 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'

【问题讨论】:

    标签: debugging syntax ipython


    【解决方案1】:

    您有两个elses 在同一缩进级别,一个接一个,这是无效的。你的意思是让其中一个成为elif

    【讨论】:

    • 好吧,我不知道。我会试试 elif 看看效果如何。我做了更改,但我有同样的错误
    • 我把第二个 else 改成了 elif
    • 只是精灵? elif 后面需要另一个表达式。
    • 还需要什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 2012-08-23
    • 2018-05-13
    • 2018-12-23
    • 1970-01-01
    相关资源
    最近更新 更多