Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python 3.4 Programming help please Blackjack Dice Blackjack is usually played wi

ID: 667624 • Letter: P

Question

Python 3.4 Programming help please

Blackjack Dice Blackjack is usually played with cards. In this program we’ll be using dice to play against a dealer. The rules are fairly simple, you roll dice and total them for your score. The player who has the highest total without going over 21 wins.

The program will start by asking the user for how much money they want in chips. This amount must be greater than 0. Before each round it should ask them for their wager amount. The wager is more than 0 and less than or equal to their pot. If the user wins a round their wager gets added to their pot. If they lose, then the pot is decremented by the wager. If there is a tie, then the pot is left alone. The player continues playing until they run out of money. In which case they can begin play again by buying more chips or quitting.

Requirements

Your program will ask the user for an initial amount of money that the user will have. This is their pot. They are allowed to keep playing as long as they have money left. The user cannot enter a value <= 0. It must be a positive whole number. Do not worry about the user entering floats or strings. We’ll learn how to deal with those later.

You should ask them how much they want to wager for each round. This amount has to be greater than zero, and less than or equal to the amount they have left. Keep prompting them for a correct amount until they have provided it. Again, we won’t worry about the user entering anything malicious at this point.

The pot and wager will be integers.

Once the initial rolls are made, ask the user if they want to roll another die. The only acceptable values are Y,YES,N or NO. Any other input give a warning and prompt for input again.

The user rolls a single die as long as they want to and it gets added to their total. If they bust ( go over 21), then they will not be asked to roll again and automatically lose.

Once the user loses all their money ( which is inevitable ), you should report how many rounds played before they lost all their money, and the maximum amount of money they had.

Once the user runs out of money ask the user if they want to play again. Valid responses are Y, YES, N or NO. If they want to play more, then they can enter another pot amount. If no, then the program ends.

If the user plays again don’t forget to reset the rounds played and maximum amount.

Development notes

To roll the dice, you need a way to generate random numbers. Fortunately, Python includes just such a feature. To use it, make the first line of 'real' code (after your opening comments): import random

To generate a random whole number from 1 to 6: d = random.randint(1,6) Obviously, you can use whatever variable name you like other than d.

The string method .lower() produces a new string that is the lowercase version of a string. 'ABC'.lower() == 'abc' It can be useful in processing some of the user input. Its use is not required.

There is also a .upper() method as well. ‘abc’.upper() produces ‘ABC’

The membership operator in can be useful as well. Its use is not required

Extra Credit ( 5 Points ) Add help at the beginning of the program. When the users is asked for an amount if they enter H, then help information explaining BlackJack Dice and what their options are will be displayed.

Explanation / Answer


tot=0
label .p
pot = int(input("Enter pot amount: "))
if (pot<=0)
goto .p

label .w
wag = int(input("Enter wager for round: "))
if (wag<=0)
goto .w

for i in range(1,4):
   n=n+random.randint(1,6)
label .c
ans=input("want to throw die")
if ans=='y':
   n=n+random.randint(1,6)
   if n>21:
       print('You lost')
       return
   else:
       goto .c

else:

print(' You Win')

pot=pot+wag