这是我的第一个程序,这只是代码的一部分,它不起作用,我不知道出了什么问题,如果有人可以帮助我,我会很开心。 当你获胜时会发生问题,而不是打印if部分,它会打印其他部分,
感谢,
` 导入重新
导入随机
def game ():
while True:
print("Welcome to heads or tails")
N = input("""Amount of money to bet :
$""")
n = int(N)
r = range (0,101,10)
if n in r:
print ("Start the game!!" )
T = input ("""How many heads?
""")
t= int(T)
a= range (0,11)
if t in a :
B = input("""How many tails?
""")
b=int(B)
if b in a and b+t== 10:
headsCount = 0
tailsCount = 0
count = 0
while count < 10 :
coin = random.randrange(2)
if coin == 0:
headsCount +=1
print ("Heads")
else:
tailsCount +=1
print ("Tails")
count +=1
score1= str(headsCount)
score2= str(tailsCount)
print (score1 + " times it was heads")
print (score2 + " times it was tails")
#Here is where i think the problem is
if headsCount==t and tailsCount==b:
print("You winn!")
else :
print("Try again, i'm sure that this time you're going to win!")
x = input("""press p to continue or q to exit
""" )
if x== ("q"):
print('godbye, see you soon!')
break
if x == ("p"):
game()
if b in a and b+t< 10:
print ("You have to select more times")
else:
print ("Multiples of 10 only")
game ()
`
答案 0 :(得分:2)
if score1==t and score2==b:
t
和b
是整数,score1
和score2
是字符串。 1}}子句永远不会是真的。
尝试将其更改为:
if