I am currently working on the coin_flip function for the ‘Games of Chance’ project, I am curious about why I am getting a response of ‘none,’ in addition to what I expect…
def coin_flip(call, bet):
print("Thank you for playing, you have bet " + str(bet) + ' dollars on ' + str(call) + '!')
num = random.randint(1, 2)
# If the coin flip is heads
if num == 1 and call == "Heads":
if call == "Heads":
return print("You win " + str(bet) + ", You made the correct call, Heads")
# If the coin flip is tails
if num == 2 and call == "Tails":
if call == "Tails":
return print("You win " + str(bet) + ", You made the correct call, Tails")
# If you lose the game
print("I'm sorry, you lost " + str(bet) +" by betting on " + str(call))
I’ve tried to work through and isolate what about the code is causing that to return, but I am stumped.
return or print? presumably you mean print since you’re seeing it, so, which print? and where did it get its value from?
do you know what order your program executes in? (you should, you wrote it) if there’s some part you don’t know which order it runs in, then perhaps inserting prints can tell you more, printing is after all how you can make measurements of what is happening in your code.
if you do know what order it executes in, then you should also be able to trace any values you’re using (your none) to where you produced it
It turns out it was due to my launching the function inside of a print statement, I can’t tell if you were trying to tell me that was what could be causing it or not but either way thanks for the help.
Wasn’t trying to hint at any source of problem, just to get you to narrow down the “when” of it and consider what was being done in that time span.
You can remove code too, so that there’s less to look at, for example a function that only produces a single result, and then use that to figure out how to invoke it and receive that result.
But yes, which does what and what behaviour were you looking for and what then was the other doing? Maybe you had code that you couldn’t argue for why it should be that way, or maybe you thought it did something else.