如何使我的游戏工作?

时间:2015-02-20 20:00:22

标签: python

import random
import sys

Hdie = "A human has fallen."

Zdie = "A zombie has fallen!"

No = "Nothing happened."

Randeve = (Hdie, Zdie, No)

NumH = int(raw_input("How many humans are on your team?"))

NumZ = int(raw_input("How many zombies are in the area?"))

if NumH >= 101:
    print "Maximum humans is 100."
    sys.exit()

if NumZ >= 121:
    print "Maximum zombies is 120."
    sys.exit()

print(random.choice(Randeve))

if Randeve == Hdie:
    print "hi"

每当我运行它并打印Hdie时,它就不会打印hi。救救我!

1 个答案:

答案 0 :(得分:4)

random.choice(Randeve)的结果分配给变量,并在适用的两个地方使用它。

x = random.choice(Randeve)
print(x)
if x == Hdie:
    print "hi"