okay, so my code is:
import random money = 100 #Write your game of chance functions here def coin_flip(call, amount): if random.randint(1,2) == 1: coin_toss = "Heads" else: coin_toss = "Tails" if call == coin_toss: result = "won" total_amount = money + amount else: result = "lost" total_amount = money - amount print( "You flipped a %s and you called %s! You %s and now have $%.2f" %(coin_toss, call, result, total_amount) ) coin_flip("Heads", 10)
and this actually works quite nicely, however I am struggling to figure out how to update the global variable “money” to represent the new amount.
I’ve tried changing the code so that instead of “total_amount = money + amount” it shows “money = money + amount” in the hopes that it would update the global variable but instead it only returns an error message stating “the local variable money has been referenced before assignment”.
Any general thoughts on the code? How do I incorporate into my function the ability to continually update the global variable “money”?