Python if statement doesn't work as expected

后端 未结 5 1857
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 22:55

I currently have the code:

fleechance = random.randrange(1,5)
print fleechance
if fleechance == 1 or 2:
    print \"You failed to run away!\"
elif fleechance         


        
5条回答
  •  忘掉有多难
    2020-12-11 23:20

    Try

    if fleechance == 1 or fleechance == 2:
        print "You failed to run away!"
    elif fleechance == 4 or fleechance == 3:
        print "You got away safely!"
    

    Alternatively, if those are the only possibilites, you can do

    if fleechance <= 2:
        print "You failed to run away!"
    else:
        print "You got away safely!"
    

提交回复
热议问题