我对编码很陌生,我从python开始。我制作了一个游戏,您得到一个数字,您必须在这个数字上加上或减去随机给出的两个选项之一的值。如果您小于0或大于21,则游戏将停止,并显示消息“您输了”。问题是,如果我输入的数字不在两个选项之间,则程序将将该值添加为anywais。
有人可以帮助我解决这个问题吗?另外,如果有人找到提高游戏效率的方法或类似的方法,我将非常感激。
import random
pos_ch = [-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
pos_i = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
count = random.choice(pos_i)
print("You start with: " + str(count))
while count in range(22):
a = random.choice(pos_ch)
b = random.choice(pos_ch)
print("Choose one of those two options: ")
print(a,b)
chn_num = int(input())
if chn_num == a or b:
count += chn_num
else:
print("Please, choose ONLY one of those TWO options:")
chn_num2 = int(input())
count += chn_num2
print("Your new number is: " + str(count))
else: print('You lost')
谢谢:)