Python无效语法错误..IF语句

时间:2018-10-16 17:14:47

标签: python syntax-error

db.lv1.aggregate([
  { "$sort": { _id: 1 } },
  { "$lookup": {
    "from": "lv2",
    "let": { "lv1_id": "$_id" },
    "pipeline": [
      { "$sort": { index: 1 } },
      { "$match": { "$expr": { "$eq": [ "$lv1_id", "$$lv1_id" ] } } },
      { "$lookup": {
        "from": "lv3",
        "let": { "lv2_id": "$_id" },
        "pipeline": [
          { "$sort": { index: 1 } },
          { "$match": { "$expr": { "$eq": [ "$lv2_id", "$$lv2_id" ] } } }
        ],
        "as": "children"
      }}
    ],
    "as": "children"
  }}
]);

'''这是我得到的错误'''

    p1 = float(input("Enter your first number: "))
    op = input("Enter a operator: ")
    p2 = float(input("Enter your second number: "))

    if op == "+":
        print(p1 + p2)
    elif op == "*":
        print(p1 * p2)
    elif op == "/":
        print(p1 / p2
    elif op == "-":
        print(p1 - p2)
    else:
        print("Invalid Operator")

SyntaxError:语法无效

1 个答案:

答案 0 :(得分:1)

#表示评论。

p1 = float(input("Enter your first number: "))
op = input("Enter a operator: ")
p2 = float(input("Enter your second number: "))

if op == "+":
    print(p1 + p2)
elif op == "*":
    print(p1 * p2)
elif op == "/":
    print(p1 / p2)
elif op == "-":
    print(p1 - p2)
else:
    print("Invalid Operator")