Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


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

CS119 Python Programming PJ 3 – Roll 2 Dice Game Please write a Python program to let you or the user play the game of rolling 2 dice and win/lose money

Computer Science

CS119 Python Programming

PJ 3 – Roll 2 Dice Game

Please write a Python program to let you or the user play the game of rolling 2 dice and win/lose money.  Initially, you have 100 dollars in your account, and the dealer also has 100 dollars in his/her account. You would be asked to enter a bet to start the game.  If your bet is zero, the game would be stopped immediately. Otherwise, dealer would roll 2 dice and get a number from ( random.randint(1, 6) + random.randint(1, 6) ).   You would roll 2 dice and get a number from ( random.randint(1, 6) + random.randint(1, 6) ).   Now, compare your number with the dealer’s number to see who would won the bet amount and who would lose the bet amount.  If you lose, the bet would be deducted from your account, and the same bet would be added to the dealer’s account.  If you won, the bet would be added to your account, and the same bet would be deducted from the dealer’s account.  If it is a tie, neither your account nor dealer’s account would be touched.  Then, continue the game with the same bet amount automatically until either your account or dealer’s account has a zero or negative balance.  Then, show the final result of both accounts’ balance, and stop the game.

Please note that you must not get a number from random.randint(2, 12) because ( random.randint(1, 6) + random.randint(1, 6)  ) is more random and fair to roll 2 dice between the dealer and you.

You must test your game program 3 times.  Your test case #1 should look as follows including the data.  You must also do test case #2 and test case #3 with different data.  Each test case or test run must begin with a welcome message, and must end with a thank-you message.

 

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

1 ============================================================.

Now, you have  100 dollars to play the game. Dealer also has  100  dollars.

>> Enter your bet to roll 2 dice for this complete game (enter 0 to quit): 50

2 ============================================================.

Roll 2 dice twice: Dealer got  5 , and you got  9 .

You won. Now, you have  150 dollars, and dealer has  50  dollars.

3 ============================================================.

Roll 2 dice twice: Dealer got  12 , and you got  10 .

You lost. Now, you have  100 dollars, and dealer has  100  dollars.

4 ============================================================.

Roll 2 dice twice: Dealer got  8 , and you got  8 .

It’s tie. Now, you have  100 dollars, and dealer has  100  dollars.

5 ============================================================.

Roll 2 dice twice: Dealer got  7 , and you got  6 .

You lost. Now, you have  50 dollars, and dealer has  150  dollars.

6 ============================================================.

Roll 2 dice twice: Dealer got  11 , and you got  4 .

You lost. Now, you have  0 dollars, and dealer has  200  dollars.

7 ============================================================.

Game ends. You have  0  dollars, and dealer has  200  dollars.

8 ============================================================.

Thank you for playing this Rolling 2 Dice Game of Dr. Simon Lin? must use your name

9 ============================================================.

 

You may use the following framework to complete your program.

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

# Author: Dr. Simon Lin    < < - - You must use your name here as the author.

# Date:    9/01/2021

# Purpose: To play a game of rolling 2 dice between dealer and you, and win/lose money.

# MAIN PROGRAM: ====== Python does not use main( ) to start the main program.

import random   # import library to use random.randint( )

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

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

print(n,"=========================================================."); n+=1; # increment n by 1

yourMoney = 100      # you have 100 dollars to start.

dealerMoney = 100   # dealer also has 100 dollars to start.

print( "Now, you have ", yourMoney, "dollars to play the game. Dealer also has ", dealerMoney, " dollars.")

bet = int(input("Enter your bet to roll 2 dice for this complete game (enter 0 to quit): "))  # convert to integer for bet

if bet == 0 :

   exit( ) # to stop this game and exit immediately

while True:  # keep running forever until break is encountered.

   dealer = random.randint(1, 6) + random.randint(1, 6)  # dealer rolls the dice twice to get 2 numbers

   you = random.randint(1, 6) + random.randint(1, 6) # you roll the dice twice to get another 2 numbers

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

   print("Roll 2 dice twice: Dealer got ", dealer , ", and you got ", you , "." )

# your Python statements here:

# if dealer > you:   # You lost.

#      dealerMoney will be increased by the bet.

#      yourMoney will be deducted by the bet.

# elif you > dealer:  # You won. 

#      dealerMoney will be decreased by the bet.

#      yourMoney will be increased by the bet.

# else :      # you == dealer     

#      It is a tie.

#      Neither you nor dealer will earn or lose the bet. 

   if dealerMoney <= 0 or yourMoney <= 0 :   # either side has no money to play

      break # time to exit the while loop and stop this game now.  Game is really over.

   # end of while True loop

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

print("Game ends. You have ", yourMoney, " dollars, and dealer has ", dealerMoney, " dollars. ")

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

print("Thank you for playing this Rolling 2 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 ============================================.

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

Python programming notes:

  1. After you copy the above code (from Word document) into Visual Studio, you will see “unexpected indent error” pointing to the first line of the code.  One simple way to solve this problem is to delete the first blank character of every line.
  2. You must indent your code properly for each if and while statement.

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

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 show 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-PJ3.py ), and

       (b) Your WORD document (for example, CS119-PJ3-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 3 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. 

     // 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 to be captured.

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

 

 

Test Case #1: Bet must be 50.

 

Test Case #2: Bet must be 25.

 

Test Case #3: Bet must be 75

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE