0

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 ()
1
  • 2
    Not an answer to your question, but make sure you put your import statements at the beginning of your script, not in the body of the code, man. Commented Jan 7, 2016 at 20:51

1 Answer 1

3
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:
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.