Define the playround method with only the self parameter

Assignment Help Python Programming
Reference no: EM131504906

Assignment: Dice Poker

Our goal is to write a game program that allows a user to play video poker using dice. The program will display a hand consisting of five dice. The basic set of rules is as follows:

? The player starts with $100.
? Each round costs $10 to play. This amount is subtracted from the user's money at the start of the round.
? The player initially rolls a completely random hand.
? The player gets two chances to enhance the hand by rerolling some or all of the dice.
? At the end of the hand, the player's money is updated according to the following payout schedule:

? Two Pairs = $5
? Three of a Kind = $8
? Full House (A Pair and a Three of a Kind) = $12
? Four of a Kind = $15
? Straight (1-5 or 2-6) $20
? Five of a Kind = $30

1. Now we are ready to turn our attention to the task of actually implementing the poker game. We know that the PokerApp will need to keep track of the dice and the amount of money. Let's initialize these values in the constructor.

1. Define a new class named PokerApp in the same file as the Dice class.

2. Inside the PokerApp define an init method that only has one parameter, self.

3. Inside the init method, create an instance of the Dice class, Dice(), and store the instance in an instance variable called dice. Remember to precede the instance variable with self and a dot.

4. Inside the init method, create an instance variable named money and initialize it to 100. Remember self-dot.

5. To test the PokerApp class and its contructor use the following driver code:

1. game = PokerApp()

2. print game.money

3. Printing the dice instance variable is a little more tricky. Try it by adding the following code to the driver code above:

1. print game.dice

2. This doesn't work because the dice instance variable is an object. To print the value inside the object you must use dot notation and call the instance variable on that object. Change the last line of code to:

1. print game.dice.dice

2. Now we want to loop the program allowing the user to continue playing hands until he or she is either out of money or chooses to quit. Sincee it costs $10 to play a hand, we can continue as long as the amount of money is at least $10.

1. Define a method called wantToPlay that has a parameter self.

1. Inside the method, use raw_input to ask the user "Do you wish to try your luck?" and store the result in a local variable named ans.

2. Now we need to see if the user responded with "yes" or "y". If the first letter of ans is uppercase or lowercase "y" then return True, otherwise return "False." Hint: The first letter of a string is index zero.

2. Define another method called run with a parameter, self.

1. Inside the method, ouput the following: You currently have $100.

2. Inside the method, create a loop that executes as long as the money balance is at least $10 and a call to the wantToPlay method is true. Don't forget the self-dot.

3. Inside the loop make a call to a method named playRound and send no arguments.

3. Most of the work of the program has now been pushed into the playRound method. Each round will consist of a series of rolls. Based on these rolls, the program will have to adjust the player's score.

1. Define the playRound method with only the self parameter.

2. Inside the playRound method, subtract 10 from the money.

3. Make a call to another instance method called doRolls that takes no arguements. This method will be in charge rolling the dice and rerolling if the user chooses. We will write this method in the next section.

4. When control returns from the doRolls method we will have the final hand to be played so we need to score the hand by calling the score method in the dice class. To do this we must use call the method using the dice instance variable (don't forget the self-dot). The score method will return two values: the type of hand and the payout. So here's how it will look:

1. result, score = self.dice.score()

5. Print the values returned by the score method according to this sample output: Full House. You win $12.

6. Add the payout to the player's money.

7. Print the new amount player money according the following sample output: You currently have $102.

4. Finally, we are down to the nitty-gritty details of implementing the dice rolling process.

Initially, all of the dice will be rolled. Then we need a loop that continues rolling user-selected dice until either athe user chooses to quit rolling or the limit of three rolls is reached.

1. Roll all the dice using the roll method in the Dice class.

2. Create a local variable to keep track of the roll number. Initialize this variable to 1 since we are on the first roll.

3. Print the roll of the dice using the following sample: Dice: [2, 3, 2, 1, 5, 5]

4. Get input from the user asking for which dice to reroll and store in a local variable named toRoll: toRoll = input("Enter list of which to change ([] to stop) ")

5. Create a loop that will execute as long as the roll count is less than three and the user didn't type in an empty list to stop.

1. Inside the body of the loop, call the roll method of the dice class rolling the dice the user selected.

2. Increment the roll count by 1.

3. Output the new hand of rolled dice. Use the same code as earlier.

4. Create a conditional statement that asks the user if they want to roll again but only if the roll count is still less than three.

5. Your PokerApp class should now be complete. To run the game you should only need to create a PokerApp object and then call its run method. These commands should not be part of the class and therefore should not be indented.

1. game = PokerApp()
2. game.run().

Reference no: EM131504906

Questions Cloud

Modes of human inquiry and expression : How do you distinguish humanities from other modes of human inquiry and expression?
Projects by applying the irr rule : A firm evaluates all of its projects by applying the IRR rule.
What is the project average accounting return : You’re trying to determine whether or not to expand your business by building a new manufacturing plant. what is the project’s average accounting return (AAR)?
Imagine a racially democratic society : Imagine a racially democratic society. What would that look like? How would your daily life be different in such a society? Record your reflections.
Define the playround method with only the self parameter : Define the playRound method with only the self parameter. Make a call to another instance method called doRolls that takes no arguements.
Discuss a general overview of yourself : Discuss in detail the experience you had in class in the development of your academic and career-related skills.
Initial investment in fixed assets when evaluating project : What is the proper cash flow amount to use as the initial investment in fixed assets when evaluating this project?
Explain respiratory system and circulaatory system : Explain respiratory system and circulaatory system
Subject covered cyber bullying : Complete a 5-7 page final paper that analyzes the future impact of this social problem you have mentioned in the second writing assignment.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd