Question

Python Program Write a simple dice game. The game starts by giving the player $250. The...

Python Program

Write a simple dice game. The game starts by giving the player $250. The game prompts the player for the amount they want to bet, and the sum of two randomly rolled dice. If the player guesses the sum correctly, the player wins some money based on the rules below. If the player guesses wrong, the player loses the amount that was bet. The game repeats until either the player runs out of money, or the player chooses to stop playing.

Here are the rules for winning and losing.

  • If the sum matches the sum of the dice, and the two dice have the same value, the winning amount is twice the bet. For example, if the player bets $100, and the player guesses four as the sum, and first die is two and second die is two, then the player is awarded $200, which is twice the bet of $100.
  • If the sum matches the sum of the dice, but the two die have different values, then the winning amount is the same as the bet.
  • If the player guesses the wrong sum, he loses the amount equal to the bet.

Ensure that:

  • The player does not bet more than they have, or a negative amount. If the amount is negative or greater than the amount they have, ask the player to reenter the bet.
  • The player types Y, y, N or n when prompted to continue the game. If the player enters anything else, the game should ask the player to reenter the answer.

Homework Answers

Answer #1

Explanation::

  • Code in PYTHON is given below
  • Screenshots of the Code is also provided
  • Screenshots of the OUTPUT are given at the end of the code


Code in PYTHON::

import random
balance=250
betAmount=0
sumGuess=0
while True:
    if balance==0:
        print("You do not enough balance!")
        break
    dice1=random.randint(1,6)
    dice2=random.randint(1,6)
    sumRandom=dice1+dice2
    while True:
        betAmount=int(input("Enter how much money you are betting:"))
        if betAmount<=0 or betAmount>balance:
            print("Invalid Amount! Please Enter Again.\n")
        else:
            break
    sumGuess=int(input("Enter your guess for sum of two rolled dice : "))
    if(sumGuess==sumRandom):
        if dice1==dice2:
            print("\nJumbo Jackpot You are Rewarded DOUBLE bet Money!")
            balance=balance+(2*betAmount)
        else:
            print("\nYou guess the sum correct! You are Rewarded the bet Money!")
            balance=balance+betAmount
    else:
        print("\nYou guess was wrong! Better luck next time!")
        balance=balance-betAmount
    print("Your current balance is",balance)
    playAgain='y'
    while True:
        playAgain=input('Do you want to play again? Enter Y/y for yes else N/n for no:')
        if playAgain=='Y' or playAgain=='y' or playAgain=='N' or playAgain=='n':
            break
        else:
            print("Invalid Input! Enter again.")
    if playAgain=='n' or playAgain=='N':
        print("Bye!")
        break
    print("\n")

Screenshot of the CODE:

OUTPUT::

  

Please provide the feedback!!c
  
Thank You!!
  

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
One of the most popular games of chance is a dice game known as “craps”, played...
One of the most popular games of chance is a dice game known as “craps”, played in casinos around the world. Here are the rules of the game: A player rolls two six-sided die, which means he can roll a 1, 2, 3, 4, 5 or 6 on either die. After the dice come to rest they are added together and their sum determines the outcome. If the sum is 7 or 11 on the first roll, the player wins....
   Dice Game – Accumulator Pattern and Conditionals (40 pts) IN PYTHON Write a program dicegame.py...
   Dice Game – Accumulator Pattern and Conditionals (40 pts) IN PYTHON Write a program dicegame.py that has the following functions in the following order: in python Write a function roll that takes an int n and returns a random number between 1 and n inclusive. Note: This function represents a n sided die so it should produce pseudo random numbers. You can accomplish this using the random module built into python.         (3 pts) Write a function scoreRound that...
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
1.Joe is playing a game of chance at the hibiscus festival, costing $1 for each game....
1.Joe is playing a game of chance at the hibiscus festival, costing $1 for each game. In the game two fair dice are rolled and the sum of the numbers that turned up is found. If the sum is seven, then Joe wins $5. Otherwise loses his money. Joe play the game 15 times. Find his expected profit or lose? 2. The basketball player has a 75% chance of a successful shot. The shots are assumed to be independent of...
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps...
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps is a game played with a pair of dice. In the game, the shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the “coming out” roll) is a 7 (“natural”) or 11 (“yo-leven”), the shooter immediately wins the game. If the coming out...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT