它总是印着你会是一个了不起的主教练和运气将永远在你身边。如果这不是真的,它甚至会这样做
usinp = input ("Which scenario would you like to do first 1,2, or 3?")
if usinp == "1":
print ("You are playing the Packers in OT of the 2014 NFC championship team.")
firplay = input ("It's your ball on the Seattle 13. The defense is in cover 2. What play do you want to run? HB gut, Hail Mary, or WR screen pass?")
if firplay == "HB gut":
import random
_1 = "Yay you scored a 93 yard touchdown. This scenario is over. YOU WIN"
_2 = "You Gained 3 yards now it is 2nd and 7 from your own 16"
_3 = "Your team commited a turnover. This scenario is over. YOU LOSE!"
PossibleOutcomes = [_1,_2,_3]
def example():
print (random.choice(PossibleOutcomes))
if "Yay you scored a 93 yard touchdown. This scenario is over. YOU WIN" in PossibleOutcomes:
print ("You would be an amazing head coach and luck will always be on your side")
elif "You Gained 3 yards now it is 2nd and 7 from your own 16" in PossibleOutcomes:
print("It's your ball on the Seattle 16. The defense is in cover 2. What play do you want to run? Bubble catch, Strong HB toss, Hail Mary?")
else:
print("You would be a horrible head coach your team would never make the playoffs and you will be fired.")
example()
似乎您没有正确保存随机选择的结果,这就是为什么只有if语句被执行的原因。您需要检查随机选择的结果是否与if或elif或else语句匹配。所以这是逻辑问题。:)
只需简单地做
哦,顺便说一句,欢迎来这里。:)还有一个额外的提示:不管它看起来如何,如果和else语句没有任何问题,它总是你的逻辑的一小部分。打印变量值是从调试的角度检查正在发生的事情的最简单的方法。:)
让我们逐行检查代码:D
你怎么解决这个问题?只需要得到一个变量来记住所做的随机选择。你知道吗
将
def example():
后面的部分替换为:TL;DR:用
choice = random.choice(possibleOutcomes)
print(choice)
替换print(random.choice(possibleOutcomes))
,然后用== choice
替换in possibleOutcomes
。祝你今天愉快:D你实际上没有储存你的选择。您的测试是检查第一个字符串是否在选项的
list
中,而不是它是否被选中;因为第一个字符串总是在选项的list
中,所以第一个块总是激发,不包括其他被测试的块。对于极简修复:相关问题 更多 >
编程相关推荐