This code must be in Python: START OF PLAY The player starts with 100 points. They have ten attempts (or rounds) to reach 500 points to win. Each round, the player "bets" some amount of points. See gameplay as follows: A HIGH/LOW ROUND (1) The player is shown an initial random card. Cards have a value from 2-14; however, these values are converted to a string as follows: 2-9 are converted to their string equivalent "2", "3", ... "9" 10 is "T", 11 is "J", 12 is "Q", 13 is "K" and 14 is "A" (2) After the play sees the first card, they should guess if the next card will be higher (i.e., greater than the current card) or lower (i.e., a lower value than the first card). They will do this by inputting "H" or "L" (lowercase "h" and "l" will also be accepted as valid input). (3) After they input their "high" or "low" guess, the player bets a number of points that their guess will be right. The bet must be between 1 and the total amount of points the player has.1 (4) After the bet amount is entered, a second card will be randomly generated. If the player was right about their guess (high or low) they win the bet amount; otherwise, they lose the amount the bet amount. The bet amount will be added or deducted from their overall points. Question: What if the second card is the same value as the first? You still lose because it isn't higher or lower. (5) The game keeps going until the player points go to 0 (i.e., they lose all their points) or the player wins 500 points or more. If the player cannot get to 500 points within ten (10) rounds, they also lose. STOPPING CRITERIA (1) [WIN] If the player reaches 500 or more points, stop and let them know how many rounds it took them. (2) [LOSE] If the player runs out of points (i.e., points is 0), stop the game and let them know what round they ran out of points. (3) [LOSE] If they have not reached 500 or more points after ten rounds, let them know the final number of points they have and that they made it to 10 rounds. 2. Implementation Details As mentioned in Section 1, you need to implement specified functions five (5) functions. Note – you can have more functions, but you should have these five (5) implemented as specified. getCardValue() This function will return a random number between 2-14. It takes no parameters. getCardStr(cardValue) Parameter cardValue is an integer between 2-14. This function will convert the integer to a string as follows. Integers 2 to 9 are converted to "2" .. "9" 10 to "T", 11 to "J", 12 to "Q", 13 to "K", and 14 to "A" Return: The function returns a string. getHLGuess() This function will repeatedly ask the player "High or Low (H/L)?:" The function should repeat get input until either a "H", "h", "L" or "l" is entered. Return: Depending on what is entered, return the string "HIGH" or the string "LOW". NOTE – you don't return "H" or "L", the function should return the string "HIGH" or "LOW" getBetAmount(maximum) Parameter maximum is an integer that represents the maximum a player can bet. This maximum should be the player's current number of points they have. This function will repeatedly ask the player "Input bet amount: " Check to make sure the amount is between 1 and maximum. If the amount is less than 0 or over the maximum, ask the player to enter again. Return: This function should return the amount the user entered. playerGuessCorrect(card1, card2, betType) Parameters card1 and card2 represent the integer values of the two cards. Parameter betType is a string that is either "HIGH" or "LOW". Depending on the betType, see if the player was correct. For example, if the betType was "HIGH" and Card1 > Card2, then the user was incorrect (False). Think carefully about all the cases for the player to be right or wrong. Return: return True or False (Boolean) depending on if the guess was right. Remember, if both cards are equal, the guess is wrong (False) Main Program Use the functions above as appropriate in the main program. An outline of the flow of the main program is provided. You do not have to use the main() function approach as shown in the notes; however, you are welcome to do so. Also, your functions and main program must all be implemented in a single file. We will not be using the module approach (it will come later in this class). Main program 1. Print out a welcome message, set initial points to 100 2. While the gameplay is valid (i.e., stopping criteria not reached) 3. Show the current amount of points and what round it is (see examples/video) 4. Get the first card, print out its string value (see examples/video) 5. Get the players High/Low guess 6. Get the players bet 7. Get the second card, print out its string value (see examples/video) 8. Check to see if players guess was correct (either True or False) 9. If the guess was True, the bet is added to the overall points; otherwise, deduct the bet amount 10. Printout the round result as shown in the examples and video (see examples/video) 11. Loop back to 2
This code must be in Python:
START OF PLAY
The player starts with 100 points. They have ten attempts (or rounds) to reach 500 points to win. Each round, the player "bets" some amount of points. See gameplay as follows:
A HIGH/LOW ROUND
(1) The player is shown an initial random card.
Cards have a value from 2-14; however, these values are converted to a string as follows: 2-9 are converted to their string equivalent "2", "3", ... "9"
10 is "T", 11 is "J", 12 is "Q", 13 is "K" and 14 is "A"
(2) After the play sees the first card, they should guess if the next card will be higher (i.e., greater than the current card) or lower (i.e., a lower value than the first card).
They will do this by inputting "H" or "L" (lowercase "h" and "l" will also be accepted as valid input).
(3) After they input their "high" or "low" guess, the player bets a number of points that their guess will be right. The bet must be between 1 and the total amount of points the player has.1
(4) After the bet amount is entered, a second card will be randomly generated. If the player was right about their guess (high or low) they win the bet amount; otherwise, they lose the amount the bet amount.
The bet amount will be added or deducted from their overall points.
Question: What if the second card is the same value as the first? You still lose because it isn't higher or lower.
(5) The game keeps going until the player points go to 0 (i.e., they lose all their points) or the player wins 500 points or more. If the player cannot get to 500 points within ten (10) rounds, they also lose.
STOPPING CRITERIA
(1) [WIN] If the player reaches 500 or more points, stop and let them know how many rounds it took them.
(2) [LOSE] If the player runs out of points (i.e., points is 0), stop the game and let them know what round they ran out of points.
(3) [LOSE] If they have not reached 500 or more points after ten rounds, let them know the final number of points they have and that they made it to 10 rounds.
2. Implementation Details
As mentioned in Section 1, you need to implement specified functions five (5) functions.
Note – you can have more functions, but you should have these five (5) implemented as specified.
getCardValue()
This function will return a random number between 2-14.
It takes no parameters.
getCardStr(cardValue)
Parameter cardValue is an integer between 2-14.
This function will convert the integer to a string as follows. Integers 2 to 9 are converted to "2" .. "9"
10 to "T", 11 to "J", 12 to "Q", 13 to "K", and 14 to "A" Return: The function returns a string.
getHLGuess()
This function will repeatedly ask the player "High or Low (H/L)?:"
The function should repeat get input until either a "H", "h", "L" or "l" is entered. Return: Depending on what is entered, return the string "HIGH" or the string "LOW".
NOTE – you don't return "H" or "L", the function should return the string "HIGH" or "LOW"
getBetAmount(maximum)
Parameter maximum is an integer that represents the maximum a player can bet.
This maximum should be the player's current number of points they have.
This function will repeatedly ask the player "Input bet amount: "
Check to make sure the amount is between 1 and maximum. If the amount is less than 0 or over the maximum, ask the player to enter again.
Return: This function should return the amount the user entered.
playerGuessCorrect(card1, card2, betType)
Parameters card1 and card2 represent the integer values of the two cards.
Parameter betType is a string that is either "HIGH" or "LOW".
Depending on the betType, see if the player was correct.
For example, if the betType was "HIGH" and Card1 > Card2, then the user was incorrect (False). Think carefully about all the cases for the player to be right or wrong. Return: return True or False (Boolean) depending on if the guess was right.
Remember, if both cards are equal, the guess is wrong (False)
Main Program
Use the functions above as appropriate in the main program. An outline of the flow of the main program is provided. You do not have to use the main() function approach as shown in the notes; however, you are welcome to do so. Also, your functions and main program must all be implemented in a single file. We will not be using the module approach (it will come later in this class).
Main program
1. Print out a welcome message, set initial points to 100
2. While the gameplay is valid (i.e., stopping criteria not reached)
3. Show the current amount of points and what round it is (see examples/video)
4. Get the first card, print out its string value (see examples/video)
5. Get the players High/Low guess
6. Get the players bet
7. Get the second card, print out its string value (see examples/video)
8. Check to see if players guess was correct (either True or False)
9. If the guess was True, the bet is added to the overall points; otherwise, deduct the bet amount
10. Printout the round result as shown in the examples and video (see examples/video)
11. Loop back to 2
Step by step
Solved in 3 steps with 6 images