Codecademy Forums

Https://www.codecademy.com/practice/projects/games-of-chance

Hi all,

how can i make my code return the value that is typed after return, running all the code i have after return and then it also prints “none” which is the valued that was returned?

thank you

//////////////////// code below \\\\\\\\\\\

import random

money = 100


#Write your game of chance functions here
def coin_flip(guess, bet):
  num = random.randint(1, 2)
  if num == 1:
    num = "Heads"
  if num == 2:
    num = "Tails"
  print(num)
  
  profit = bet * 2
  loss = bet / 2
  
  if guess == num:
    return (print("You have won this match. Your guess was " + str(guess) + " and your bet was " + str(bet) + ". Your winnings for this match are " + str(profit) + " and your new total is " + str(money + profit)))
  elif guess != num:
    return (print("You lost this match. Your guess was " + str(guess) + " and your bet was " + str(bet) + ". Your losses for this match are " + str(loss) + " and your new total is " + str(money - loss)))
  else:
    return "You must chooese either head or tails"
  
print(coin_flip("Heads", 100))

return is a statement, so don’t use parentheses:

return "some value"

and using print and return at the same line is really confusing. Do either, not both.

the none is caused by the fact that the print() functions returns None (although, technically None indicates the absence of a return value)

1 Like