Hi guys, I am attempting to make an if statement that if returns true it informs the user that they have entered an option incorrectly and will prevent the function from running any further.
The code is seen below:
def cho_han(guess, bet):
global money
dice_roll_1 = random.randint(1, 6)
dice_roll_2 = random.randint(1, 6)
dice_result = dice_roll_1 + dice_roll_2
print("You have guessed " + str(guess) + " best of luck!")
if guess != "even" and "odd":
return "Whoops! you have entered your choice incorrectly! try entering either odd or even to continue"
elif dice_result % 2 == 0 and guess == "even":
money = money + bet
return "The combined dice rolls were even, congratulations! You have won £" + str(bet) + "!\n" + "You now have £" + str(money) + " in your account."
elif dice_result % 2 <= 0 and guess == "odd":
money = money + bet
return "The combined dice rolls were odd, congratulations! You have won £" + str(bet) + "!\n" + "You now have £" + str(money) + " in your account."
else:
money = money - bet
return "Unfortunately you have guessed incorrectly, better luck next time.\n" + "You now have £" + str(money) + " in your account."
With the call to the function looking something like this:
print(cho_han("odd", 30))
However everytime I call the function it always returns the first if statement.
You have guessed odd best of luck!
Whoops! you have entered your choice incorrectly! try entering either odd or even to continue
Not sure how to get round this issue, when I used it in my first function it worked perfectly fine.
Any help would be appreciated.
Thankyou.