Code below, but basically when I run the function, it will go through every step when I win, but when I lose, it will skip the final else statement it seems? Any tips would be great as i’m a bit lost!

import random
money = 100
#Write your game of chance functions here
def coin_toss(bet, guess):
#Need to ensure that the bet is higher than 0 first
if bet <= 0:
print("Your bet needs to exceed 0 to play.")
return 0
#Flip the coin
print("Okay, let's flip! You guessed " + guess)
coin_result = random.randint(0,1)
#Show the result to the user?
if coin_result == 0:
print("Heads!")
elif coin_result == 1:
print("Tails!")
#Calculates the result
if (coin_result == 0 and guess == "Heads") or (coin_result == 1 and guess == "Tails"):
print("You win $" + str(bet) + ", well done!")
return bet
else:
print("Better luck next time! You lost $" + str(bet) + ".")
return -bet
#Call your game of chance functions here
coin_toss(5, guess = "Tails")

I believe this is because your indentation is not correct.

the part that calculates the result only looks to be working if the result is tails because it is indented that way. and you get the win result because you test your function on tails.

coin_toss(5, guess = "Heads")
this however would never calculate the results cause that part is only accessible when it lands tails.

I don’t get this project at all in the first place. In your code-

import random
money = 100
#Write your game of chance functions here
def coin_toss(bet, guess):
#Need to ensure that the bet is higher than 0 first
if bet <= 0:
print("Your bet needs to exceed 0 to play.")
return 0

Why did you return zero in the function coin_toss()? I don’t get the reason for it.

import random
total = 100
def coin_flip(guess, bet):
# coin_flip code here
def higher_card(bet):
# higher_card code here
def cho_han(guess, bet):
# cho_han code here
def roulette(guess, bet):
# roulette code here
total += coin_flip("Heads", 10)
total += higher_card(5)
total += cho_han("Even", 2)
total += roulette("Even", 10)
total += roulette(3, 1)
total += roulette("Odd", total)
print("Your total amount of money is " + str(total))

… so that all of the total += function_call() statements at the bottom run sequentially; if one of the bets is bad (i.e., < = 0), the expression is still expecting a number. If it instead receives None or a string like “Bad bet”, the script will halt with a TypeError. The way it is written, it will continue despite the “bad bet.”