# Heads and Tails Game with money

Hi, I’m trying to work through the games of chance project https://www.codecademy.com/practice/projects/games-of-chance
Please could you review my code and tell me where I’m going wrong. I know my attempt is probably awful but I’ve tried this for 3 hours total now and this is my best attempt.
I’m currently getting a syntax error when I call my function.

``````import random

money = 100

num = random.randint(1, 2)

#Write your game of chance functions here

print("Your Balance is £" + str(money))

def game(bet, guess):

if bet <= 0:

print("Invalid Bet")

return 0

elif bet > 0:

print("You bet on" + guess)

coin_result = random.randint(1, 2)

if coin_result == 1:

print("The Coin was flipped and it's Tails")

elif coin_result == 2:

print("The Coin was flipped and it's Heads")

#choosing winner

if coin_result == 1 and guess == " Tails" or coin_result == 2 and      guess == " Heads":

print("You Win £" + str(bet))

new_balance_if_won = money =+ bet

print("You now have £" + str(new_balance_if_won))

else:

print("You lost £" + str(bet))

new_balance_if_lost = money =- bet

print("You now have £" + str(new_balance_if_lost)

game(10, guess = " Tails")
``````

I am going to refer to a question I answered 2 hours ago:

very different exercise, but exactly the same problem

1 Like

So simple, thank you

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.