短版本:即使猜测等于答案,猜测评估为假。
长版本:我是编码的新手,正在尝试制作经典的玫瑰花瓣游戏。我制作了游戏,但它始终表明正确的猜测是错误的。我有它,所以玩家的猜测输入等于答案,然后它应该说你是对的。如果你错了,它会打印正确的答案。我尝试了游戏并输入了正确的猜测,但它说我错了,即使它表明我输入了正确的答案,所以它应该评估为真,并打印我是正确的。如果有人可以提供帮助,我会感激不尽。这可能是一个简单的错误,但我已经查看了一段时间,看看是否有人理解为什么它应该评估为真时评估为假。这段代码是使用3.5完成的。
print ("These are the dice we will be using.")
import dice
dice.display_dice(2,3,4,5,6)
print ("These are the dice you have rolled.")
import random
die1 = random.randint (1,6)
die2 = random.randint (1,6)
die3 = random.randint (1,6)
die4 = random.randint (1,6)
die5 = random.randint (1,6)
dice.display_dice(die1, die2, die3, die4, die5)
answer = 0
#Since the only dice that add petals are 3 and 5, I just count how many times those numbers appear and ad 2 to the answer each time.
if die1==3:
answer = answer + 2
if die2==3:
answer = answer + 2
if die3==3:
answer = answer + 2
if die4==3:
answer = answer + 2
if die5==3:
answer = answer + 2
if die1==5:
answer = answer + 4
if die2==5:
answer = answer + 4
if die3==5:
answer = answer + 4
if die4==5:
answer = answer + 4
if die5==5:
answer = answer + 4
#For some reason, when I input the right guess, it says it's wrong, even though it shows the guess is the same as the answer
guess = input("Guess how many petals are around the rose: ")
if guess==answer:
print ("You are correct. The answer is ", guess)
elif guess!=answer:
print ("You're wrong. The answer is ", answer)