# Craps Example # Source code file random/craps.rb # Simulate a Craps dice game. import random balance = int(input("How many dollars worth of" \ " chips do you want to purchase? ")) play_again = "yes" while play_again == "yes": print(f"Your current chip balance is ${balance}.") bet = int(input("Enter amount of bet: ")) # Get return string "\n" but throw it away input("Press enter to roll dice:") die1 = random.randrange(1, 7) die2 = random.randrange(1, 7) sum = die1 + die2 print(f"Roll: {die1} {die2}. Sum: {die1 + die2}.") if sum == 7 or sum == 11: print("You win.") balance = balance + bet elif sum == 2 or sum == 3 or sum == 12: print("You lose.") balance = balance - bet else: # Establish point point = sum print(f"Point is established to be {sum}.") # Get return string "\n" but throw it away input("Press enter to roll dice:") die1 = random.randrange(1, 7) die2 = random.randrange(1, 7) sum = die1 + die2 print(f"Roll: {die1} {die2}. Sum: {die1 + die2}.") while sum != 7 and sum != point: # Get return string "\n" but throw it away input("Press enter to roll dice:") die1 = random.randrange(1, 7) die2 = random.randrange(1, 7) sum = die1 + die2 print(f"Roll: {die1} {die2}. Sum: {die1 + die2}.") if sum == point: print("You win.") balance = balance + bet elif sum == 7: print("You lose.") balance = balance - bet print("Do you want to play again?")