Python3 ParseError

时间:2017-10-20 20:36:08

标签: python parse-error

我正在尝试做一个简单的任务,一个脚本可以确定输入的数字是最小的。这是代码:

largest = None
smallest = None

while True:
    num = input("Enter a number: ")
    if num == "done" : 
        break
    try :
        num = int(num)
    except :
        print('Invalid input')
        continue

    if smallest is None :
        smallest = num
    elif: 
        smallest > num
        smallest = num

    if largest is None :
        largest = num
    elif :
    largest < num
    largest = num



print("Maximum", largest)

当我尝试运行代码时,它告诉我&#39; ParseError:第15行的错误输入&#39;

有人能帮帮我吗?

1 个答案:

答案 0 :(得分:2)

elif的正确语法与普通if语句的语法相同:

而不是:

elif: 
    smallest > num
    smallest = num

执行:

elif smallest > num:
    smallest = num

对于您的其他elif进一步向下。