Python:有条件的'如果'声明设定利率

时间:2016-01-23 21:28:08

标签: python

我制作的游戏中用户必须拍摄入侵的敌人。

我试图通过检查当前分数来提高敌人产生的速度。但是我不断收到错误。

这是我的代码:

 for x in range(score):

     if score is > 5 and < 10:
           spawnrate = 6
     elif score is > 10 and < 20:
           spawnrate = 8
     elif score is > 20:
           spawnrate = 10

4 个答案:

答案 0 :(得分:2)

select#graph_line_duration{ height: 24px; font-size: 10px; } 不正确,虽然可以将比较链接在一起,但你也做错了。

使用

is

或(更明确地)

if 5 < score < 10:

答案 1 :(得分:1)

不是针对低值和高值测试每个案例,而是让if - 案例级联,如

if score < 5:
    spawnrate = 4
elif score < 10:
    spawnrate = 6
elif score < 20:
    spawnrate = 8
else:
    spawnrate = 10

答案 2 :(得分:0)

删除is,您必须使用and

两次使用变量
 if score > 5 and score < 10:
       spawnrate = 6
 elif score > 10 and score < 20:
       spawnrate = 8
 elif score > 20:
       spawnrate = 10

答案 3 :(得分:0)

该行:

$.each(result.data, function () {
   //alert(this.hubID);
   hubList.push(this.hubID);
}.bind(this)); // <- force the loop to use the object context of your choice

应该是:

elif score > 10 and score < 20:

另外,python允许你做这样的事情:

elif score > 10 and score < 20: