 # Cho-Han Challenge: How do I make game loop until player selects stop?

creted the 2nd Part of the challenge (Cho-Han Game) and i want to give the player the option of continuing or stopping. whats the best way to code this? Below is my code:

``````import random

cash = 100

print('\n')
print("Hello: " + name)
print("Lets Play a Game of Cho-Han!!! ")
print("Available cash winnings: " + "\$", cash)
odd_or_even = str(input("Please enter odd or even: "))

def cho_han(odd_even, wager_amount):
print("You placed: " + "\$", place_wager, " Dollars on: ", odd_or_even)
print('\n')

dice_1 = random.randint(1, 6)
dice_2 = random.randint(1, 6)

roll = input("Press *Enter* to roll both dice ")
print(roll)
print('\n')
print("Dice 1 = ", dice_1)
print("Dice 2 = ", dice_2)
print('\n')

sum_of_two_dice = (dice_1 + dice_2) % 2

if sum_of_two_dice == 0 and odd_even == "even":
cash_total = wager_amount + cash
print("Demo - (でも) - Even")
print("Anata wa kachimasu - (あなたは勝ちます) - You Won!!!", cash_total)
return cash_total
if sum_of_two_dice == 0 and odd_even == "odd":
cash_total = wager_amount + cash
print("Kawatta - (変わった) - Odd")
print("Anata wa kachimasu - (あなたは勝ちます) - You Won!!!", cash_total)
return cash_total
else:
cash_total = cash - wager_amount
print("Anata no makedesu - (あなたの負けです) - Sorry, You Lost!!!", cash_total)
return cash_total

cho_han(odd_or_even, place_wager)

``````

Thank You!!!

See my post near the bottom of this thread.

I notice there’s no decision to keep playing after the function completed, why?

1 Like

There are two functions, menu() and game_play(). If you put them in the same script as your coin_flip() and cho_han() functions, and then call game_play(100), you’ll see that after each game you are given the choice to keep on playing, choose which game, and place your bet. (Of course, as we discussed elsewhere, it won’t run in the CodeAcademy IDE due to the input() functions.)

The original intent was just to preserve and update the bank, but it should be easily modifiable if it doesn’t do what you want. There are many, many ways to code this sort of thing; obviously this is only one.

1 Like

thanks, I plan on adding a GUI to this code but right now I just want to be a master Python 3 fundelmetalist. Ive been running my code in Pycharm.

Thanks
geekmonster

2 Likes