Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Cho-Han Game
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import random, sys

NUMBERS = {1: 'ONE', 2: 'TWO', 3: 'THREE', 4: 'FOUR', 5: 'FIVE', 6: 'SIX'}

print('''In this traditional Japanese dice game, two dice are rolled in a bamboo
cup by the dealer sitting on the floor. The player must guess if the
dice total to an even (cho) or odd (han) number.
''')

purse = 5000
while True: # Main game loop.
# Place your bet:
print('You have', purse, 'money. How much do you bet? (or QUIT)')
while True:
pot = input('> ')
if pot.upper() == 'QUIT': #even if quit is written in small letters
print('Thanks for playing!')
sys.exit()
elif not pot.isdecimal():
print('Please enter a number.')
elif int(pot) > purse:
print('You do not have enough to make that bet.')
else:
# This is a valid bet.
pot = int(pot) # Convert pot to an integer.
break # Exit the loop once a valid bet is placed.

# Roll the dice.
dice1 = random.randint(1, 6)
dice2 = random.randint(1, 6)


print('CHO (even) or HAN (odd)?')

# Let the player bet cho or han:
while True:
bet = input('> ').upper()
if bet != 'CHO' and bet != 'HAN':
print('Please enter either "CHO" or "HAN".')
continue
else:
break

# Reveal the dice results:
print('The dealer lifts the cup to reveal:')
print(' ', NUMBERS[dice1], '-', NUMBERS[dice2])
print(' ', dice1, '-', dice2)

# Determine if the player won:
rollIsEven = (dice1 + dice2)
if rollIsEven % 2 == 0:
correctBet = 'CHO'
else:
correctBet = 'HAN'

playerWon = bet

# Display the bet results:
if playerWon == correctBet:
print('You won! You take', pot, 'money.')
purse = purse + pot # Add the pot from player's purse.
print('The house collects a', pot // 10, 'mon fee.')
purse = purse - (pot // 10) # The house fee is 10%.
else:
purse = purse - pot # Subtract the pot from player's purse.
print('You lost!')

# Check if the player has run out of money:
if purse == 0:
print('You have run out of money!')
print('Thanks for playing!')
sys.exit()