In: Computer Science
USE PYTHON ONLY
Please write a Python program to let you or the user play the game of rolling a dice and winning/losing money. Initially, you have 100 dollars in your account. You place a bet to roll the dice. The game will be stopped if your bet is zero. First, dealer would roll the dice and get a number from random.randint(1, 6). Then, you would roll the dice and get a number from random.randint(1, 6). Now, compare your number with dealer’s number to see whether you won or lose the bet. If you lose, the bet would be deducted from your account. If you won, the bet would be added to your account. If it’s a tie, your account is not touched. Then, continue the game of putting your bet until your bet is zero. The game is to continue even when you have zero or negative amount of money. You must test your game program 3 times with at least 10 rounds for each game. The output of your test case #1 may like as follows: Welcome to the Rolling Dice Game of TM
1 =============================================. Now, you have 100 dollars to play the game.
2 =============================================. Enter your bet to roll the dice (enter 0 to quit): 10 Dealer got 1 , and you got 5 . You won 10 dollars. Now, you have 110 dollars.
3 =============================================. Enter your bet to roll the dice (enter 0 to quit): 5 Dealer got 5 , and you got 3 . You lost 5 dollars. Now, you have 105 dollars.
4 =============================================. Enter your bet to roll the dice (enter 0 to quit): 30 Dealer got 3 , and you got 3 . It's a tie. Now, you have 105 dollars.
5 =============================================. Enter your bet to roll the dice (enter 0 to quit): 200 Dealer got 3 , and you got 4 . You won 200 dollars. Now, you have 305 dollars.
6 =============================================. Enter your bet to roll the dice (enter 0 to quit): 100 Dealer got 4 , and you got 1 . You lost 100 dollars. Now, you have 205 dollars.
7 =============================================. Enter your bet to roll the dice (enter 0 to quit): 205 Dealer got 2 , and you got 6 . You won 205 dollars. Now, you have 410 dollars.
8 =============================================. Enter your bet to roll the dice (enter 0 to quit): 400 Dealer got 3 , and you got 6 . You won 400 dollars. Now, you have 810 dollars.
9 =============================================. Enter your bet to roll the dice (enter 0 to quit): 500 Dealer got 4 , and you got 1 . You lost 500 dollars. Now, you have 310 dollars.
10 =============================================. Enter your bet to roll the dice (enter 0 to quit): 310 Dealer got 6 , and you got 2 . You lost 310 dollars. Now, you have 0 dollars.
11 =============================================. Enter your bet to roll the dice (enter 0 to quit): 10 Dealer got 3 , and you got 6 . You won 10 dollars. Now, you have 10 dollars.
12 =============================================. Enter your bet to roll the dice (enter 0 to quit): 40 Dealer got 3 , and you got 1 . You lost 40 dollars. Now, you have -30 dollars.
13 =============================================. Enter your bet to roll the dice (enter 0 to quit): 0
14 =============================================. Thank you for playing the Rolling Dice Game of TM
15 =============================================.
CODE:
import random
money = 100 # defines the initial money which the user has
quit = 1 # if the value of quit is 0 game quits
i = 2
print("1 =============================================. Now, you have 100 dollars to play the game.")
while quit != 0: # iterating using while while loop
print(i,"=============================================. Enter your bet to roll the dice (enter 0 to quit):",end=" ")
bet = int(input()) # taking the input from the user
if bet == 0: # if user select 0 then ending the game
print(i,"=============================================. Thank you for playing the Rolling Dice Game of TM")
quit = 0
continue
user = random.randint(1,6) # else creating two random values between 1 to 6
dealer = random.randint(1,6)
if user>dealer: # case where user wins
money += bet
print(i,"Dealer got",dealer,", and you got",user,". You won",money," dollars")
elif dealer>user: # where dealer wins
money -= bet
print("Dealer got",dealer,", and you got",user,". You lost",money," dollars")
else: # when the game ties
print("Dealer got",dealer,", and you got",user,". It's a tie. You have",money," dollars")
i+=1 # its for just knowing the number of iterations

