So I am in the middle of one of the projects that you get “challenge project” and have run into a problem. Basically, I am trying to get a game that allows people to bet “odd” or “even” and wager money on it. The way I wrote this, it is supposed to return the result of the roll (odd or even) and then display a message stating that the user either won the bet or lost it depending on what argument they entered in the wager parameter. Here is the code:
def cho_han_game(): dice_roll_1 = random.randint(1,6) dice_roll_2 = random.randint(1,6) total_roll = dice_roll_1 + dice_roll_2 if total_roll % 2 == 0: return "even" else: return "odd" def cho_han_guess(wager,bet_amount): if wager == cho_han_game(): return str(cho_han_game()) + " Congratulations, you wagered " + str(bet_amount) + " dollars and won " + str(bet_amount) + " and increased your total money to " + str(money + bet_amount*2) + " dollars, you won the bet!" else: return str(cho_han_game()) + " Oh no! You bet " + str(bet_amount) + " dollars and guessed incorrectly, decreasing your total money to " + str(money - bet_amount) + " You lost the bet!" #Call your game of chance functions here print(cho_han_guess("even",20))
So right now, the issue is that while the code certainly seems to work, the money is deducted/added appropriately and the message will change between the congratulations and the sorry messages, the result doesn’t always add up to what was entered by the user as an argument. For example, in this code, the print call to the function “cho_han_guess” enters the argument “even”. if I run the code, the console will sometimes print that the result of “cho_han_game” was “odd” yet still display the congratulations message. My best guess? The “cho_han_game” function that is printing to the console is not the same “cho_han_game” function that is running “invisibly” with the “cho_han_guess” function. And I’m not entirely sure why this is. I have tried running “cho_han_game” and “cho_han_guess” under a single function, but it seems to terminate the function after the Boolean operator for whether the roll is odd or even executes, never continuing to the Boolean operators for the user inputs. Again, not sure why. Please help!