Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / CS119 Python Programming PJ 4 – Roll Dice Game Please write a Python program to let you or the user play the game of rolling a dice and winning/losing money

CS119 Python Programming PJ 4 – Roll Dice Game Please write a Python program to let you or the user play the game of rolling a dice and winning/losing money

Computer Science

CS119 Python Programming

PJ 4 – Roll Dice Game

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 immediately if your bet is zero.  First, dealer would roll the dice and get a number from the function call random.randint(1, 6).  Then, you would roll the dice and get a number from the function call random.randint(1, 6).   Now, compare your number with the dealer’s number to see whether you would win or lose the bet.  If you should lose, the bet would be deducted from your account. If you should win, the bet would be added to your account.  If it is 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 in your account.

You must test your game program 3 times with at least 7 rounds for each game.  The output of your test case #1 must look as follows including all the data.  You must also do test case #2 and test case #3 with different sets of data.  Each test case or test run must begin with a welcome message, and end with a thank-you message.

 

Welcome to the Rolling Dice Game of Dr. Simon Lin? must use your name

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 Dr. Simon Lin? must use your name

15 =============================================.

 

You may use the following framework to complete your game program.

#---------------------------------------------------------------------------------------------------------------.

# Author: Dr. Simon Lin    # must use your name

# Date:    12/21/2021

# Purpose: CS119-PJ4: A game to roll the dice and earn/lose money with initial money of 100 dollars

#                for you to start your game.

# MAIN PROGRAM: ============================================.

import random

n = 1  # line number for each separator line in sequence

print ("Welcome to the Rolling Dice Game of Dr. Simon Lin!" )  # must use your name

print(n,"=========================================================."); n+=1;

yourMoney = 100

print( "Now, you have ", yourMoney, "dollars to play the game.")

while True:  # keep running forever.  It must be stopped by a break inside the loop.

     print(n,"=========================================================."); n+=1;

     bet = int(input("Enter your bet to roll the dice (enter 0 to quit): "))  # get bet from the user

     # Your Python statements here:

    # if bet is zero:

    #      break out of this loop immediately to end the game;    

     dealer = random.randint(1, 6)    # dealer rolls the dice

     you = random.randint(1, 6)    # you roll the dice

     print("Dealer got ", dealer, ", and you got ", you, "." ) # show the points of both sides

     # Your Python statements here:

    # if dealer’s points is more than yours:

    #    subtract the bet from your money since you lost;     

             print("You lost " , bet, " dollars. Now, you have ", yourMoney, " dollars. ")

    # elif dealer’s points is less than yours:

    #    add the bet to your money since you won;

          print( "You won. Now, you have ", yourMoney, "dollars.")       

    # else :  # dealer’s points is equal to yours

    #    It’s a tie.  Therefore, you won or lost nothing. 

             print("It's a tie. Now, you have ", yourMoney, "dollars.")

     # end of while True loop

print(n,"=========================================================."); n+=1;

print("Thank you for playing the Rolling Dice Game of Dr. Simon Lin!")   # must use your name

print(n,"=========================================================."); n+=1;

x = input("Press Ctrl+Alt+PrtScn to get a snapshot of this console, then ENTER to exit: ")

 

# End of MAIN PROGRAM ==========================================.

 

=========================================================================.

How to submit your Project Assignment (PJ)?

(1) Each program must be well documented with block comments and proper line comments. 

     The beginning of each program must have a block comment to show its author, date, and purpose.

     The following is an example of block comments:

# Author:  _______________    ?  must use your full name here!

# Date:                                          ?  must be today’s date!

# Purpose: _______________     ?  must show the purpose of this program here!

(2) You must submit to Canvas the following two items as attachments:

       (a) Your source program (for example, CS119-PJ4.py ), and

       (b) Your WORD document (for example, CS119-PJ4-report .docx ) containing the listing of

             your Python program, and the complete output of your 3 test runs as specified.

      You must not submit a zip file to Canvas.        

=========================================================================.

//You must delete everything above & including this line to make this your Word document to be submitted.

 

PJ 4 Report                               My Name: ______________

 

A. The following is my Python source program:

       // Please copy your source program into here from your Visual Studio IDE.   

       // Your code here must be in color.  You must not show screen prints here.

 

B. The following is the console output of my 3 test runs:

     // One way to copy the console output is to press Ctrl+Alt+PrtScn, which is a screen print. 

     // Another way to copy is to use the snipping tool.  To paste the image is to press Ctrl+v.

    // The console display must not be too wide, otherwise it will be too hard to read once pasted.

     // Please make sure your console is long enough to show all your output lines, and is readable.

     // Please copy your console output and paste into here:

 

 

Test Case #1:

 

Test Case #2: At least 7 rounds.

 

Test Case #3: At least 7 rounds.

Option 1

Low Cost Option
Download this past answer in few clicks

22.99 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE