Hey guys, I am trying to create a try and except statement for the coin flip game of chance however everytime I try to run the program it is coming up with a syntax error as follows:
File "script.py", line 12
Try:
^
SyntaxError: invalid syntax
Here is the function I am trying to implement it into:
def coin_flip(guess, bet):
global money
coin_flip = random.choice(['Heads', 'Tails'])
#randomly generates heads or tails choice.
if coin_flip == 'Heads':
for entry in guess:
Try:
bet = 'Heads!'
break
except:
print("Whoops! you haved typed the choice in incorrectly, try either heads or tails")
money = money + bet
return "Congratulations, you guessed correctly! You have won £" + str(bet) +"!\n" + "You now have £" + str(money) + " in your account."
else:
money = money - bet
return "Unfortunately you have lost £" + str(bet) + " better luck next time\n" + "You now have £" + str(money) + " in your account."
If anybody can help on this it would be really appreciated.
Thankyou.