为什么python会为变量添加更多而不是需要?

时间:2017-10-09 20:07:21

标签: python

我正在制作一个刽子手游戏,当我运行代码时,一切都有效,除了胜利线。 lengthr 是来自当前猜测的字词的字母数量,长度 lengthr 需要匹配的实际数量。如果我有一个5个字母的单词 lengthr 最终将大约为9,这就是我需要帮助的地方。

    import turtle
    import random

    w1 = "battery"
    w2 = "report"
    w3 = "beach"
    w4 = "mayor"
    w5 = "score"
    w6 = "overeat"
    w7 = "load"
    w8 = "social"
    w9 = "honor"
    w10 = "risk"

    turns = 10
    guesses = ''
    err = 0

    gennum = random.randint(1, 10)

    if gennum == 1:
        usedw = w1
    elif gennum == 2:
        usedw = w2
    elif gennum == 3:
        usedw = w3
    elif gennum == 4:
        usedw = w4
    elif gennum == 5:
        usedw = w5
    elif gennum == 6:
        usedw = w6
    elif gennum == 7:
        usedw = w7
    elif gennum == 8:
        usedw = w8
    elif gennum == 9:
        usedw = w9
    elif gennum == 10:
        usedw = w10

    wn = turtle.Screen()
    draw = turtle.Turtle()

    length = len(usedw)
    lengthr = int(0)

    print("Welcome to hangman your word is", length, "letters long.")

    while turns > 0:
        guess = input("Choose a character: ")
        guesses += guess
        for char in usedw:
            if char in guesses:
                print (char,)
                lengthr += 1
        else:
            err += 1
            if err == 1:
                draw.goto(0,0)
                draw.down()
                draw.goto(200,0)
            elif err == 2:
                draw.up()
                draw.goto(0,0)
                draw.down()
                draw.goto(0,200)
            elif err == 3:
                draw.up()
                draw.goto(0,200)
                draw.down()
                draw.goto(100,200)
            elif err == 4:
                draw.up()
                draw.goto(100,200)
                draw.down()
                draw.goto(100,150)
            elif err == 5:
                draw.up()
                draw.goto(100,100)
                draw.down()
                draw.circle(25)
            elif err == 6:
                draw.up()
                draw.goto(100,100)
                draw.down()
                draw.goto(100,50)
            elif err == 7:
                draw.up()
                draw.goto(75,90)
                draw.down()
                draw.goto(125,90)
            elif err == 8:
                draw.up()
                draw.goto(100,50)
                draw.down()
                draw.goto(75,35)
            elif err == 9:
                draw.up()
                draw.goto(100,50)
                draw.down()
                draw.goto(125,35)
                print("You loose.")
                break
            if lengthr == length:
                print ("You won!")     

1 个答案:

答案 0 :(得分:1)

您应该在for char in usedw:循环之前设置$commentquery=mysqli_query($con,"SELECT * FROM user_comments WHERE content_id='$storyid' ORDER BY date DESC LIMIT 5 "); $count = mysqli_num_rows($commentquery); while ($count > 0) { $count--; mysqli_data_seek($commentquery, $count); $comment = mysqli_fetch_array($commentquery): // do things with $comment }