ELIF,ELSE语法错误python 3.2.1

时间:2016-09-25 13:15:59

标签: python-3.x

def magic_n(guess2): #Function, have someone guess if number is 7, max 5 tries
magicn2 == 7
tries = 0
while (tries < 5) and (guess2 != magicn2):
 if guess < 7 :
    tries = tries + 1
    print("Too Low")
    guess2 = int(input("Give me another number since the last one was too high : "))
    elif guess > 7:
    tries = tries + 1
    print("Too high")
    guess2 = int(input("Give me another number since the l ast one was too low : ")
    else :
    print("Good job you got it")

guess2 = int(输入(&#34;请给我一个号码:&#34;) 打印(magic_n(guess2)

道歉,如果这种提问方式不对,首次使用堆栈溢出

3 个答案:

答案 0 :(得分:1)

身份不正确,你需要再做一个括号,否则#34;。

所以它会是:

db.ratings.aggregate([
    { 
        "$match": {
            "book": {
                "$in": [
                    ObjectId("57e111142a52fe257e5d1d42"), 
                    ObjectId('57e6bef7cad79fa38555c643')
                ]
            }
        }
    },
    { 
        "$group": {
            "_id": { 
                "book": "$name",
                "rating": "$rating"
            },
            "count": { "$sum": 1 }
        }
    },
    { 
        "$group": {
            "_id": "$_id.book",
            "counts": {
                "$push": {
                    "rating": "$_id.rating",
                    "count": "$count"
                }
            }
        }
    }
])

答案 1 :(得分:1)

是缩进....

当你使用python时......我建议你看看PYCHARM,因为你可以避免将来出现这样的错误。我经常使用它并自动格式化。

https://www.jetbrains.com/pycharm/

答案 2 :(得分:0)

第12行:

guess2 = int(input("Give me another number since the l ast one was too low : ")) //bracket missing

缩进必须在python中是正确的。在python中没有}所以代码片段需要了解我的块在哪里开始以及它在哪里结束 所以

if condition:
   ........
   ........
elif condition :
   ........
   ........
else :
   ........