我有下面的代码,可以用。但我被列表依赖所震撼 从0开始索引。也就是说
当用户选择1时,它将使用第0个元素 当用户选择2时,它取第一个元素 当用户选择3时,它需要第二个元素。。我不能再这样下去了。你知道吗
我想克服这一点,但不是像任何黑客内部转换给定的text=text-1。请帮忙。有其他解决办法吗
import numpy as np
Ran=[np.random.randint(1,5)]
Val=Ran[0]
print(Val)
#Items
items=['1. pot plant','2. painting','3. vase','4. lampshade','5. shoe']
print ("\n")
#Intro Text
print ("Last night you went to sleep in the comfort of your own home.")
print ("Now, you find yourself locked in a room. You don't know how")
print ("you got there or what time it is. In the room you can see")
print ("\n")
print (len(items), "Things:")
for x in items:
print (x)
print ("")
print ("The door is locked. Could there be a key somewhere?")
print ("Enter the corresponding number of thing which you \
would like to check..Yougot only 3 chances !! ")
k=0
while (k==0):
Ins1 = int(input())
if (Ins1 == Val):
print("You're Lucky! Got the key in First instance ")
break
else:
c=items[Ins1]
print("Damn ! key is not available in ", c , "Try again..")
Ins2 = int(input())
if (Ins2 == Val):
print("Got the key on your 2nd attempt")
break
else:
c=items[Ins2]
print("Bad luck ! Try again..not in ", c ,"your last attempt")
Ins3 = int(input())
if (Ins3 == Val):
print("Finally you got the key")
break
else:
c=items[Ins3]
print("you're done. Die here :( Key not in ",c,)
break
相关问题 更多 >
编程相关推荐