我已经试了很久了如何让这件事起作用。它应该选择一个“从随机进口随机范围”的随机数,然后是'x = randrange(1,3)行‘。我在其他时候使用过这个生成器,但它当时起作用了,但是它不适用于这样的情况:/。这是代码:
from random import randrange
numberboy == randrange(7,9)
if numberboy == "7":
print ("You unluckily fall into a pit!")
health -= 1
if health == "1":
print ("You drop to your knees and lie, filled with pain in the pit. You drop to the floor. Your quest is over.")
print ("Your health has fallen to " + str(health) + ". ")
if numberboy == "8" or "9":
print ("You could have fallen into a pit but you luckily didn't!")
print ("You find a path leading of to another room.")
print ("You walk down the path and find a light illuminating an elvish sword!")
print ("You walk out of an escape path and find youself coming out of a secret entrance at the clearing.")
import time顺便说一句,在前面使用'numberboy = 0‘以使其工作(数字男孩是变量x)
发布于 2015-02-13 17:07:13
你把一个数字比作一个字符串..。
使用:
if numberboy == 7:而不是:
if numberboy == "7":与健康相同,请使用此比较:
if health == 1:而且,这是错误的:
if numberboy == "8" or "9":用这个代替:
if numberboy == 8 or numberboy == 9:希望这能有所帮助
发布于 2015-02-13 17:10:39
我注意到了几件事:
numberboy == randrange(7,9)应该是numberboy = randrange(7,9)NameErrornumerboy == 7而不是numberboy == '7'发布于 2015-02-13 17:10:56
numberboy == randrange(7,9)是你的问题。代之以
numberboy = randrange(7,9)randrange(x,y)会给出这样的数字x <= nb < y,所以不可能是y
https://stackoverflow.com/questions/28504838
复制相似问题