Reputation: 13
This is my first program and this is just the part of the code that's not working. I don't know what is wrong and if someone can help me I will be happy. The problem happens when you win, instead of printing the if
part, it prints the else
part.
import re
import random
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 ()
Upvotes: 0
Views: 75
Reputation: 76184
if score1==t and score2==b:
t
and b
are integers, and score1
and score2
are strings. A string will never compare equal to an integer, so your if
clause will never be true.
Try changing it to:
if headsCount==t and tailsCount==b:
Upvotes: 3