Question

In: Computer Science

USE PYTHON ONLY Please write a Python program to let you or the user play the...

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 =============================================.

Solutions

Expert Solution

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


Related Solutions

Please use Python 21. Rock, Paper, Scissors Game Write a program that let's the user play...
Please use Python 21. Rock, Paper, Scissors Game Write a program that let's the user play the game of rock, paper, scissors against the computer. The program should work as follows: 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen...
Please write in python Use modular design to write a program that asks the user to...
Please write in python Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. PLANET CONVERSION FACTOR Mercury 0.4155 Venus 0.8975 Earth 1.0000 Moon 0.1660 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899 The...
Write a program using Python that allows the user to play a guessing game (please provide...
Write a program using Python that allows the user to play a guessing game (please provide a picture of code so it is easier to read). The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: Normally, we would have the program select a random number as the "secret number". However, for the purpose of testing your program (as well as grading it), simply use an assignment...
C++ Please For this assignment, you will write a program that lets the user play against...
C++ Please For this assignment, you will write a program that lets the user play against the computer in a variation of the popular blackjack car game. In this variation of the game, two-six sided dice are used instead of cards. The dice are rolled, and the player tries to beat the computer's hidden total without going over 21. Here are some suggestions for the game's design: Each round of the game is performed as an iteration of a loop...
Please write in Python code please: Write a program that asks the user to enter 5...
Please write in Python code please: Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main: calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores determine_grade – The function should accept a test score as...
Write a program to allow a user to play the game Hangman. DO NOT USE AN...
Write a program to allow a user to play the game Hangman. DO NOT USE AN ARRAY The program will generate a random number (between 1 and 4581) to pick a word from the file - this is the word you then have to guess. Note: if the random number you generate is 42, you need the 42nd word - so loop 41 times picking up the word from the file and not doing anything with it, it is the...
PYTHON Let n denote an integer entered by the user. Write a program to print n...
PYTHON Let n denote an integer entered by the user. Write a program to print n multiples of 5 in the descending order, with the last number being 5. Print the average of those n multiples
Use Visual Python or equivalent, to write a program that allows the user to observe the...
Use Visual Python or equivalent, to write a program that allows the user to observe the following: Damped and forced harmonic oscillators. The program should be user friendly and have default values for the initial velocities, positions, masses, and spring constants as well as damping constants. Values and frequencies for the forced oscillators should also be given. It should allow the user to input values for the velocities, positions, spring constants, and masses. The program should determine automatically the scale...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program should display a letter grade for each score and the average test score. Hint: Declare local variables under main() program Prompts the user to enter 5 test scores Define a function to calculate the average score: this should accept 5 test scores as argument and return the avg Define a function to determine the letter grade: this should accept a test score as argument...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT