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.
Ensure that:
Explanation::
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!!
Get Answers For Free
Most questions answered within 1 hours.