COMP 1043编程设计 写作、Python程序

” COMP 1043编程设计 写作、Python程序UO Problem Solving and ProgrammingProgramming Assignment 3IntroductionThis document describes the first assignment for Problem Solving and Programming.The assignment is intended to provide you with the opportunity to put into practice what you have learnt in the course by applying your knowledge and skills to implement a game of Blackjack.This document is a kind of specification of the required end product that will be generated by implementing the assignment. Like many specifications, it is written in English and hence will contain some imperfectly specified parts. Please make sure you seek clarification if you are not clear on any aspect of this assignment.Assignment OverviewYou are required to write a Python program that allows a player to play a game of Blackjack against the computer. The program will allow a player to play as many games of Blackjack as they wish.BlackjackBlackjack is a popular card game where the goal is to beat the dealer by having the higher hand which does not exceed 21. httpss://en.wikipedia.org/wiki/Blackjack.Although there are many variations of the rules and game play, we will be adhering to the following rules and game play for the assignment.Blackjack hands are scored by their point total, calculated by adding together the face values of each card dealt. The hand with the highest total wins, as long as it doesnt exceed 21. A hand with a higher total than 21 is said to bust. Being dealt an Ace (of any suit) counts as eleven (11) points unless this would cause the player to bust, in which case it is worth one (1) point. Picture cards (King, Queen and Jack) are all worth 10 points. All other cards are worth their numerical value shown on the card.Blackjack game play:To begin, the player and the dealer are dealt an initial hand of two cards each.If the dealer has Blackjack (the first two cards dealt total 21 points) and the player does not, the dealer automatically wins.If the player has Blackjack (the first two cards dealt total 21 points) and the dealer does not, the player automatically wins.If both the player and the dealer have Blackjack (the first two cards dealt total 21 points) then it is a push (draw).If neither have Blackjack, then the player plays out his/her hand. Note that the term Blackjack can only be achieved as a result of the first two cards dealt.When the player has finished playing out his/her hand, the dealer (in this case the computer) plays out the dealers hand.During the players turn, the player is faced with two options either:1.Hit (take a card):After the initial deal of two cards, a player may choose to receive additional cards as many times as he/she wishes, adding the point value of each card to his/her hand total.2.Stand (end their turn):Do not receive any more cards. The players turn is over.The player repeatedly takes a card until, the player chooses to stand, or the player busts (that is, exceeds a total of 21). The players turn is over after deciding to stand or if he/she busts.Once the player has finished, the dealer plays out his/her hand (in this case the computer), revealing the hidden second card amount. Note: the dealer always plays his/her hand regardless of what happens with the players hand. The dealer must hit until he or she has a point value of 17 or greater.Blackjack rules:If the player busts, he/she loses even if the dealer also busts.If the player and the dealer have the same point value, it is called a push and neither win the hand (draw).An initial two-card deal of 21 (an 11 plus a 10) is called Blackjack (i.e. an 11 plus a 10 is dealt as the very first hand) and wins the round automatically.An Ace counts as eleven (11) points unless this would cause the player/dealer to bust, in which case it is worth one (1) point.House rules:The dealer must hit until he or she has a point value of 17 or greater.The player can not stand on a point value less than 15.The player with the higher hand that does not exceed 21 wins the game!You do not have to write the code that deals one card at a time, a module containing the function that does that for you has been provided. The playing_cards.py file is a module that contains a function called deal_one_card() that deals one card at a time for you. The function returns a string (containing two characters) that represents a card; the first letter represents the face value of the card and the second letter represents the suit. For example: it may return the two character string AH, where A represents Ace and H represents Hearts; TC, where T represents Ten and C represents Clubs, 7S, where 7 represents the card value of 7 and S represents Spades, etc. You are required to use this as part of this assignment, however, please do not modify the playing_cards.py file. There are other functions within the module that create the playing deck, and shuffle it, but you do not have to worry about those functions, you only have to make use of the deal_one_card() function in your solution, the other functions will take care of the rest for you! : )Practical RequirementsIt is recommended that you develop this assignment in the suggested stages.It is expected that your solution MUST include the use of the following:Your solution in a file called your_email_id.py.The supplied playing_cards.py module (containing the deal_one_card() function). This is provided for you please DO NOT modify this file.The deal_one_card() function (provided in the supplied playing_cards.py module).Appropriate and well constructed while and/or for loops (as necessary).Appropriate if, if-else, if-elif-else statements (as necessary).List of strings to represent the players hand, i.e. player_hand = []List of strings to represent the dealers hand, i.e. dealer_hand = []Practical requirements (continued) Your solution MUST include the use of the following:The following functions:odisplay_details()This function takes no parameters and does not return any values. The function displays your details to the screen. Remember that defining the function does not execute the function you will need to call the function from the appropriate place in the program. Your function should produce the following output (with your details) to the screen:File : wayby001.pyAuthor : BatmanStud ID : 0123456XEmail ID : wayby001This is my own work as defined by the Universitys Academic Misconduct Policy.oget_hit_choice()This function takes no parameters and returns the users choice, whether to hit (h) or stand (s). The function prompts for, reads and validates the users choice to either hit or stand.oget_play_choice(prompt_text)This function takes a string (the prompt text) to display to the screen as a parameter and returns the users choice, whether to play again, i.e. y or n. The function prompts for, reads and validates the users choice to keep playing (y) or stop playing (n).odiplay_hand(hand_text, hand)This function takes a string (hand text) to display to the screen and a list of strings (hand) containing the cards dealt. The function does not return any values and displays the hand (list) to the screen in the following format, for example:If the player_hand list is as follows,player_hand = [4D, TS, KD]calling the display_hand() function like sodisplay_hand(\nPlayer\s hand is, player_hand)will produce the following output to the screen:Players hand is 24: 4 of Diamonds | 10 of Spades | K of DiamondsIf the dealer_hand list is as follows,dealer_hand = [KS, 9C]calling the display_hand()function like sodisplay_hand(\nDealer\s hand is, dealer_hand)will produce the following output to the screen:Dealers hand is 19: K of Spades | 9 of ClubsThis function must call function get_hand_total(hand).oget_hand_total(hand)This function takes a list of strings (containing the cards dealt) and calculates the point value of the hand. The function returns the total point value of the hand.oplay_player_hand(player_hand)This function takes a list of strings (containing the cards dealt) and returns the total point value of the players hand. The function plays out the players hand until the player either busts or chooses to stand. Do not let the player stand on a value less than 15 and display the player busts message if the player exceeds 21. The function must call the following functions: get_hit_choice(), get_hand_total(), display_hand() and deal_one_card().oplay_dealer_hand(dealer_hand)This function takes a list of strings (containing the cards dealt) and returns the total point value of the dealers hand. The function plays out the dealers hand until the dealer has a point value of 17 or greater. Display the dealer busts message if the dealer exceeds 21.The function must call the following functions: get_hand_total(), display_hand() and deal_one_card().Output that strictly adheres to the assignment specifications. If you are not sure about these details, you should check with the Sample Output provided at the end of this document.Good programming practice:oConsistent commenting, layout and indentation. You are to provide comments to describe: your details, program description, all variable definitions, and every significant section of code.oMeaningful variable names.Your solutions MUST NOT use:break, or continue statements in your solution. Do not use the quit() or exit() functions or the break or return statements (or any other techniques) as a way to break out of loops. Doing so will result in a significant mark deduction.PLEASE NOTE: You are reminded that you should ensure that all input and output conform to the specifications listed here; if you are not sure about these details you should check with the sample output provided at the end of this document or post a message to the discussion forum in order to seek clarification.Please ensure that you use Python 3 (current version) in order to complete your assignments. Your programs MUST run using Python 3 (i.e. current version).StagesIt is recommended that you develop this assignment in the suggested stages. Many problems in later stages are due to errors in early stages. Make sure you have finished and thoroughly tested each stage before continuing.The following stages of development are recommended:Stage 1You will need the playing_cards.py file for this assignment. This has been provided for you. Please download this file from the course website (Assessment tab) and ensure that it is in the same directory as your yourEmailId.py file.Test to ensure that this is working correctly by entering the following in your yourEmailId.py file:import playing_cardscard = playing_cards.deal_one_card()print(card)Run the yourEmailId.py file. If this is working correctly, you should now see the following output in the Python shell when you run your program:The function deal_one_card() returns a string (containing two characters) that represents a card; the first letter represents the face value of the card and the second letter represents the suit. For example: it may return the two character string AH, where A represents Ace and H represents Hearts; TC, where T represents Ten and C represents Clubs, 7S, where 7 represents the card value of 7 and S represents Spades, etc. In the above example, the deal_one_card() function returned 6D, where 6 represents the card value of 6 and D represents Diamonds, i.e. 6 of Diamonds.Please note: the two character string returned from the function call to deal_one_card() may differ when you run your code the deck is shuffled after all! : )Also, this is for developmental purposes only, and you will need to modify and correctly position the above code.Make sure the program runs correctly. Once you have that working, back up your program. Note: When developing software, you should always have fixed points in your development where you know your software is bug free and runs correctly.Stage 2To begin, the player is dealt two cards. Use the deal_one_card() function to simulate the dealing of the players hand. You will need to create a list to store the cards (strings of two characters) returned from the call to function deal_one_card(), i.e. player_hand = []. You may use the append() method in order to add cards to the player_hand list (as seen below). Display the player_hand (list containing the two cards) to the screen.import playing_cardsplayer_hand = []# Deal first cardcard = playing_cards.deal_one_card()# Append it to the player_hand listplayer_hand.append(card)# Deal second cardcard = playing_cards.deal_one_card()# Append it to the player_hand listplayer_hand.append(card)# Display the players hand to the screen using a simple print statementprint(player_hand)Sample output:[4C, 2H]The above is displayed for testing purposes only. Eventually, when you know your code is working correctly, the players hand will be displayed as follows:Sample output:Players hand is 6: 4 of Clubs | 2 of HeartsStage 3To begin, the dealer is also dealt two cards. Use the deal_one_card() function to simulate the dealing of the dealers hand. You will need to create a list to store the cards (strings of two characters) returned from the call to function deal_one_card(), i.e. dealer_hand = []. You may use the append() method in order to add cards to the dealer_hand list. Display the dealer_hand (list containing the two cards) to the screen.Sample output:[7S, 5D]The above is displayed for testing purposes only. Eventually, when you know your code is working correctly, the dealers hand will be displayed as follows:Sample output:Dealers hand is 12: 7 of Spades | 5 of DiamondsStage 4Implement the function called get_hand_total(hand) see description under section titled Practical Requirements. Hint: Function get_hand_total(hand) should use a loop. Display the dealers hand and the players hand to the screen as seen below. For example:If the player_hand list is as follows,player_hand = [KH, 5C]calling the get_hand_total(hand) function like soplayer_total = get_hand_total(player_hand)will assign the value of 15 to variable player_total.If the dealer_hand list is as follows,dealer_hand = [TC, 7H]calling the get_hand_total(hand)function like sodealer_total = get_hand_total(dealer_hand)will assign the value of 17 to variable dealer_total.You can then use a simple print statement to display the player and dealer hand totals along with the lists to the screen as follows:Sample output:Dealer hand is: 17 [TC, 7H]Player hand is: 15 [KH, 5C]The above is displayed for testing purposes only. Eventually, when you know your code is working correctly, the dealer and player hands will be displayed as follows:Sample output:Dealers hand is 17: 10 of Clubs | 7 of HeartsPlayers hand is 15: K of Hearts | 5 of ClubsStage 5Implement the function called display_hand(hand_text, hand) see description under section titled Practical Requirements. Hint: Function display_hand(hand_text, hand) should use a loop and call the get_hand_total() function. Display the dealers hand and the players hand to the screen as seen below. For example:If the player_hand list is as follows,player_hand = [4D, TS, KD]calling the display_hand() function like sodisplay_hand(\nPlayer\s hand is, player_hand)will produce the following output to the screen:Players hand is 24: 4 of Diamonds | 10 of Spades | K of DiamondsIf the dealer_hand list is as follows,dealer_hand = [KS, 9C]calling the display_hand()function like sodisplay_hand(\nDealer\s hand is, dealer_hand)will produce the following output to the screen:Dealers hand is 19: K of Spades | 9 of ClubsStage 6Include code to check for Blackjack on the initial deal of two cards for both the player and dealer.If the dealer has Blackjack (the first two cards dealt total 21 points) and the player does not, the dealer automatically wins.If the player has Blackjack (the first two cards dealt total 21 points) and the dealer does not, the player automatically wins.If both the player and the dealer have Blackjack (the first two cards dealt total 21 points) then it is a push (draw).Sample output 1:Dealers hand is 10: Q of DiamondsPlayers hand is 15: 5 of Hearts | J of DiamondsDealers hand is 21: Q of Diamonds | A of Hearts*** Blackjack! Dealer Wins! ***Sample output 2:Dealers hand is 4: 4 of HeartsPlayers hand is 21: A of Clubs | Q of Clubs*** Blackjack! Player Wins! ***Sample output 3:Dealers hand is 11: A of ClubsPlayers hand is 21: K of Hearts | A of Diamonds*** Blackjack –Dealers hand is 21: A of Clubs | J of SpadesPlayers hand is 21: K of Hearts | A of Diamonds*** Blackjack! Push – no winners! ***Sample output 4:Dealers hand is 10: J of DiamondsPlayers hand is 17: 7 of Clubs | K of DiamondsPlay out players hand… coming soon… :)If neither have Blackjack, then the player plays out his/her hand – dont implement this just yet, simply display a message to the screen (as seen above in sample output 4).Stage 7Okay, now lets include code to play out the players hand. Prompt for and read whether the player would like to hit (h) or stand (s). Implement a loop which continues to simulate one card being dealt until the user enters stand (s). Display the players hand and the total hand value to the screen as seen below.Sample output:Dealers hand is 10: Q of DiamondsPlayers hand is 18: A of Diamonds | 7 of ClubsPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 22: A of Diamonds | 7 of Clubs | 4 of SpadesPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 27: A of Diamonds | 7 of Clubs | 4 of Spades | 5 of HeartsPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 29: A of Diamonds | 7 of Clubs | 4 of Spades | 5 of Hearts | 2 of SpadesPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 38: A of Diamonds | 7 of Clubs | 4 of Spades | 5 of Hearts | 2 of Spades | 9 of DiamondsPlease enter h or s (h = Hit, s = Stand): sYou may like to implement the function called play_player_hand() at this point or you may like to come back to it once you have the player playing out his/her hand correctly the decision is yours.Stage 8It does not make sense to continue rolling when the player busts (exceeds 21). Modify the loop developed in the previous stage so that it also stops looping if the player busts (exceeds 21).Sample output:Dealers hand is 4: 4 of DiamondsPlayers hand is 11: 5 of Clubs | 6 of HeartsPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 13: 5 of Clubs | 6 of Hearts | 2 of ClubsPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 19: 5 of Clubs | 6 of Hearts | 2 of Clubs | 6 of ClubsPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 29: 5 of Clubs | 6 of Hearts | 2 of Clubs | 6 of Clubs | 10 of Clubs– Player busts!Stage 9Now lets add a loop which simulates the computers turn. That is, plays out the dealers (computers) hand.Sample output 1:Dealers hand is 10: 10 of DiamondsPlayers hand is 9: 2 of Diamonds | 7 of DiamondsPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 11: 2 of Diamonds | 7 of Diamonds | 2 of ClubsPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 20: 2 of Diamonds | 7 of Diamonds | 2 of Clubs | 9 of DiamondsPlease enter h or s (h = Hit, s = Stand): sDealers hand is 20: 10 of Diamonds | J of DiamondsSample output 2:Dealers hand is 4: 4 of ClubsPlayers hand is 9: 3 of Spades | 6 of DiamondsPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 15: 3 of Spades | 6 of Diamonds | 6 of ClubsPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 17: 3 of Spades | 6 of Diamonds | 6 of Clubs | 2 of HeartsPlease enter h or s (h = Hit, s = Stand): sDealers hand is 14: 4 of Clubs | K of ClubsDealers hand is 24: 4 of Clubs | K of Clubs | J of Spades– Dealer busts!You may like to implement the function called play_dealer_hand() at this point or you may like to come back to it once you have the dealer playing out his/her hand correctly the decision is yours.Stage 10Add code which determines the winner and displays the result to the screen.Sample output 1:Dealers hand is 10: K of HeartsPlayers hand is 20: A of Clubs | 9 of DiamondsPlease enter h or s (h = Hit, s = Stand): sDealers hand is 20: K of Hearts | 10 of Hearts— Dealer: 20 Player: 20 – Push – no winners! —Sample output 2:Dealers hand is 10: K of SpadesPlayers hand is 16: Q of Diamonds | 6 of ClubsPlease enter h or s (h = Hit, s = Stand): sDealers hand is 20: K of Spades | Q of Hearts— Dealer: 20 Player: 16 – Dealer Wins! —Sample output 3:Dealers hand is 11: A of SpadesPlayers hand is 11: 6 of Diamonds | 5 of DiamondsPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 19: 6 of Diamonds | 5 of Diamonds | 8 of DiamondsPlease enter h or s (h = Hit, s = Stand): sDealers hand is 14: A of Spades | 3 of DiamondsDealers hand is 17: A of Spades | 3 of Diamonds | 3 of Hearts— Dealer: 17 Player: 19 – Player Wins! —Stage 11Add code that ensures that the player can not stand (s) on a hand value of less than 15. Notice that the player automatically rolls again when this happens (see sample output below).Sample output:Dealers hand is 10: Q of DiamondsPlayers hand is 14: 7 of Spades | 7 of DiamondsPlease enter h or s (h = Hit, s = Stand): sCannot stand on value less than 15!Players hand is 24: 7 of Spades | 7 of Diamonds | J of Hearts– Player busts!Dealers hand is 19: Q of Diamonds | 9 of Clubs— Dealer: 19 Player: 24 – Dealer Wins! —Stage 12Add yet another loop that asks the player whether they wish to play again [y|n].Stage 13Add code to keep track of how many games were played, how many were won, lost and drawn. Display this to the screen.Stage 14Add code to validate all user input. Hint: use a while loop to validate input. Implement the following functions:oget_hit_choice()This function takes no parameters and returns the users choice, whether to hit (h) or stand (s). The function prompts for, reads and validates the users choice to either hit or stand.oget_play_choice(prompt_text)This function takes a string (the prompt text) to display to the screen as a parameter and returns the users choice, whether to play again, i.e. y or n. The function prompts for, reads and validates the users choice to keep playing (y) or stop playing (n).Sample output:Would you like to play BlackJack [y|n]? pWould you like to play BlackJack [y|n]? tWould you like to play BlackJack [y|n]? yDealers hand is 10: K of DiamondsPlayers hand is 10: 3 of Diamonds | 7 of HeartsPlease enter h or s (h = Hit, s = Stand): zPlease enter h or s (h = Hit, s = Stand): jPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 13: 3 of Diamonds | 7 of Hearts | 3 of ClubsPlease enter h or s (h = Hit, s = Stand): hPlayers hand is 23: 3 of Diamonds | 7 of Hearts | 3 of Clubs | J of Spades– Player busts!Dealers hand is 15: K of Diamonds | 5 of DiamondsDealers hand is 25: K of Diamonds | 5 of Diamonds | K of Spades– Dealer busts!— Dealer: 25 Player: 23 – Dealer Wins! —That was fun!Play again [y|n]? ePlay again [y|n]? bPlay again [y|n]? nYou played 1 games!- Won: 0- Lost: 1- Drawn: 0Stage 15Finally, check the sample output (see section titled Sample Output towards the end of this document) and if necessary, modify your code so that:The output produced by your program EXACTLY adheres to the sample output provided.Your program behaves as described in these specs and as the sample output provided.Submission DetailsYou are required to do the following in order to submit your work and have it marked:oYou are required to save your .py file(s) of Assignment 3 including all supplied files into a single zip file with file name uopsp_assignment3_username.zip, where username is your university network username / email ID (e.g. karsy028) and submit your zip file via the submission point by Monday, 07 June (Week 10), 12:00 PM (Adelaide time).Ensure that your files are named correctly (as per instructions outlined in this document).Ensure that the following file is included in your submission:your_email_id.pyFor example (if your name is James Bond, your submission files would be as follows):bonjy007.pyAll files that you submit must include the following comments.## File: fileName.py# Author: your name# Email Id: your email id# Description: Assignment 2 place assignment description here# This is my own work as defined by the Universitys# Academic Misconduct policy.#Assignments that do not contain these details may not be marked.It is expected that students will make copies of all assignments and be able to provide these if required.Sample O”

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导