[SOLVED] game python shell COMP 1039

$25

File Name: game_python_shell_COMP_1039.zip
File Size: 254.34 KB

5/5 - (1 vote)

COMP 1039
Problem Solving and Programming
Programming Assignment 2
Prepared by Jo Zucco
EIBT Modifications Michael Ulpen
School of Computer and Information Science The University of South Australia
March 2018

TABLE OF CONTENTS
INTRODUCTION. 3
ASSIGNMENT OVERVIEW . 3
PART I SPECIFICATION LIST MODULE. 4
Requirements .. 5 Stages .. 6
Stage 1 6 Stage 2 7 Stage 3 7 Stage 4 7 Stage 5 7 Stage 6 8 Stage 7 8 Stage 8 8
Sample Output 9
PART II SPECIFICATION BLACKJACK..10
Requirements 11
Player Method Summary . 12
Deck Method Summary 12
Card Method Summary. 12
Stages 13
Stage 1. 13 Stage 2. 13 Stage 3. 13 Stage 4. 13 Stage 5. 14 Stage 6. 14 Stage 7. 15 Stage 8. 16 Stage 9. 16 Stage 10.. 16 Stage 11.. 16 Stage 12.. 16 Stage 13.. 17
Sample Output . 17 Useful Built-in Python Functions.. 20
SUBMISSION DETAILS ..21 EXTENSIONS AND LATE SUBMISSIONS.22 ACADEMIC MISCONDUCT ..22 MARKING CRITERIA23
PSP Assignment 2 201801 Page 2 of 24

INTRODUCTION
This document describes the second 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 the implementation of a Python module that contains a variety of list related functions and a game of Blackjack that uses classes, objects and functions.
This assignment is an individual task that will require an individual submission. You will be required to submit your work via Moodle before Friday Week 12, 11:55pm. You will also be required to present your work to your practical supervisor during your practical session held in week 12 of the study period. Important: You must attend the practical session that you have been attending all study period in order to have your assignment marked.
This document is a specification of the required programs and their output. Please ask your practical supervisor if you do not understand any part of this document or the assignment.
ASSIGNMENT OVERVIEW
There are two parts to this assignment:
Part I: List Module
You are required to implement a Python module that contains functions that manipulate lists. Please ensure that you read sections titled Part I specification below for further details.
Part II: Blackjack
You are required to write a game of Blackjack using methods and objects created from provided classes. When a game is complete, highscores will need to be recorded in a text file. Please ensure that you read sections titled Part II specification below for further details.
Please ensure that you read sections titled Part I Specification and Part II Specification below for further details.
PSP Assignment 2 201801 Page 3 of 24

PART I SPECIFICATION LIST MODULE
You are required to write a list_function.py module (containing only the functions listed below). This file is provided for you however, you will need to modify this file by writing code that implements the functions listed below. Please read the slides on modules available on the course website if you would like more information on modules.
You are required to implement a Python module containing the following functions:
length()
to_string()
count()
find()
insert_value()
remove_value()
Implement one function at a time.
Place the code that implements each function in the appropriate place in the list_function.py file.
For example, if you were implementing the length() function, you would place the code that calculates and returns the length of the list under the comment Place your code here (within the length function definition) seen below.
# Function length() place your own comments here : ) def length(my_list):
# This line will eventually be removed used for development purposes only. print(In function length())
# Place your code here
Test your function by running the list_function_test.py to ensure each function is working correctly before starting on the next function. The list_function_test.py file is a test file that contains code that calls the functions contained in the list_function.py module. Please do not modify the test file. You must test your functions with this file to ensure that they are working correctly.
Compare your output with the section titled Sample Output Part I to ensure that your function is working as it should.
PSP Assignment 2 201801 Page 4 of 24

REQUIREMENTS
It is expected that your solution will include the use of:
The supplied list_function.py module (containing the functions listed below). This is provided for you you will need to modify this file.
Functions (length, to_string, count, find, insert_value and remove_value) implemented adhering to the assignment specifications.
The supplied list_function_test.py file. This is provided for you please DO NOT modify this file.
Well constructed while loops. (Marks will be lost if you use break statements in order to exit from loops).
Well constructed for loops. (Marks will be lost if you use break statements in order to exit from loops).
Appropriate if/elif/else statements of the style used in the class notes.
Output that strictly adheres to the assignment specifications.
Good programming practice:
o Consistent commenting and code layout. You are to provide comments to describe: your details, program description, all variable definitions, all functions, and every significant section of code.
o Meaningful variable names.
Your solutions MAY make use of the following:
o Built-in functions range() and str().
o List method append() to create/build new lists. i.e. list_name.append(item).
o Concatenation (+) operator to create/build new strings.
o Comparison operators (==, !=, <, >, etc).
o Access the individual elements in a list with an index (one element only). i.e. list_name[index]. o Use of any of the functions you have written as part of the assignment. i.e. length() function.
Your solutions MUST NOT use:
o Built-in functions (other than range() and str() functions).
o Slice expressions to select a range of elements from a list. i.e. list_name[start:end]. o List methods (other than the append() method. i.e. list_name.append(item)).
o String methods.
o break, or continue statements
o quit() or exit()
Please ensure that you use Python 3.4 or later in order to complete your assignments. Your programs MUST run using Python 3.4.
PSP Assignment 2 201801 Page 5 of 24

STAGES
It is recommended that you develop this part of the 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 1
You will need both the list_function.py and list_function_test.py files for this assignment. These have been provided for you. Please download both of these files from the course website and ensure that they are in the same directory as each other.
Test to ensure that this is working correctly by opening and running the list_function_test.py file. If this is working correctly, you should now see the following output in the Python shell when you run your program:
Start Testing!
length Test
In function length()
List length: None
In function length()
List length: None
to_string Test
In function to_string()
List is: None
In function to_string()
List is: None
In function to_string()
List is: None
count Test
In function count()
None
In function count()
None
In function count()
None
find Test
In function find()
None
In function find()
None
insert_value Test
In function insert_value()
None
In function insert_value()
None
In function insert_value()
None
In function insert_value()
None
remove_value Test
In function remove_value()
None
In function remove_value()
None
In function remove_value()
None

PSP Assignment 2 201801
Page 6 of 24

length Test
In function length()
List length: None
to_string Test
In function to_string()
List is: None
In function to_string()
List is: None
count Test
In function count()
None
find Test
In function find()
None
insert_value Test
In function insert_value()
None
remove_value Test
In function remove_value()
None
End Testing!
Stage 2
Write a function called length(my_list) that takes a list as a parameter and returns the length of the list. You must use a loop in your solution. You must not use built-in functions, list methods or string methods in your solution.
Stage 3
Write a function called to_string(my_list, sep=, ) that takes a list and a separator value as parameters and returns the string representation of the list (separated by the separator value) in the following form:
item1, item2, item3, item4
The separator value must be a default argument. i.e. sep=,
You must use a loop in your solution. You must not use built-in functions (other than the range() and str() functions), slice expressions, list methods or string methods in your solution. You may use the concatenation (+) operator to build the string. You must return a string from this function.
Stage 4
Write a function called count(my_list, value) that takes a list and a value as parameters. The function searches for the value in the list and returns how many times the value appears in the list. You may assume that the elements of the list can be compared using the comparison operators ==, !=, etc. You must use a loop in your solution. You must not use built-in functions (other than the range() function), list methods or string methods in your solution.
Stage 5
Write a function called find(my_list, value) that takes a list, and a value as parameters. The function searches for the value in the list and returns the index at which the first occurrence of value is found in the list. The function returns -1 if the value is not found in the list.
PSP Assignment 2 201801 Page 7 of 24

Stage 6
Write a function called insert_value(my_list, value, insert_position) that takes a list, a value and an insert_position as parameters. The function returns a copy of the list with the value inserted into the list (my_list) at the index specified by insert_position. Check for the insert_position value exceeding the list (my_list) bounds. If the insert_position is greater than the length of the list, insert the value at the end of the list. If the insert_position is less than or equal to zero, insert the value at the start of the list. You must use a loop(s) in your solution. You may make use of the list_name.append(item) method in order to build the new list. You must not use built-in functions (other than the range() function), slice expressions, list methods (other than the append() method) or string methods in your solution.
Stage 7
Write a function called remove_value(my_list, remove_position) that takes a list and a remove_position as parameters. The function returns a copy of the list with the item at the index specified by remove_position, removed from the list. Check for the remove_position value exceeding the list (my_list) bounds. If the remove_position is greater than the length of the list, remove the item at the end of the list. If the remove_position is less than or equal to zero, remove the item stored at the start of the list. You must use a loop in your solution. You may make use of the list_name.append(item) method in order to build the new list. You must not use built-in functions (other than the range() function), slice expressions, list methods (other than the append() method) or string methods in your solution.
Stage 8
Finally, check the sample output in the section titled Sample Output Part I and, if necessary, modify your code so that:
The output produced by your program is formatted EXACTLY the same way as the sample output provided.
Your program behaves as described in these specifications and in the same way as the sample output.
PSP Assignment 2 201801 Page 8 of 24

SAMPLE OUTPUT
Sample output:
length Test
List length: 7
List length: 0
to_string Test
List is: r, i, n, g, i, n, g
List is: r-i-n-g-i-n-g
List is:
count Test
2
0
0
find Test 3
-1
insert_value Test
[one, two, three, four, five, six] [p, i, t]
[s, p, i, t]
[s, p, i, t, s]
remove_value Test
[r, i,g]
[i, n, g]
[r, i, n]

length Test
List length: 6
to_string Test
List is: 1, 7, 2, 3, 7, 7
List is: 1 7 2 3 7 7
count Test 3
find Test 1
insert_value Test
[1, 2, 3, 4, 5, 6]
remove_value Test
[1, 4, 5, 6]
End Testing!
PSP Assignment 2 201801
Page 9 of 24

PART II SPECIFICATION BLACKJACK
You are required to write a Python program called yourEmailId_game.py that allows a player to play Blackjack against a computer opponent until the player decides to stop playing.
2-Player Blackjack
We will be writing a simple implementation of a card game called Blackjack, also known as 21. The goal of the game is to draw cards that add up to a value as close as possible to 21 without exceeding it. In a standard game of 2-player Blackjack the player and the dealer are dealt 2 cards. The player decides to draw cards or stop drawing. When they want to draw a card they will say, hit me. When they want to stop drawing, they will say, stand. If they draw a card and the total value of cards in their hand exceeds 21, the player busts, which means they lose. If the player has not bust and they decide to stand, then it is the dealers turn to draw cards. The dealer has a special rule that, as soon as their hand value is equal to or greater than 17, they must stand. If the dealer exceeds 21, the dealer will bust, which means the player wins. It is possible that both the player and dealer end with the same hand value, in which case it is a draw.
When deciding which player has won or if a player has bust, the value of each card in that players hand are added together. Each number card is worth its number value. Face cards, such as Jacks, Queens and Kings are all worth 10. The Ace is an unusual card because, if the combined value with other cards in hand does not exceed 21, it will be worth 11, otherwise the Ace will be worth 1.
You are required to write a Python program, called game.py, that allows a player to play Blackjack against the computer. You must implement the provided functions, and then use them to play the game. You will need to make use of the provided module, blackjack.py and the classes defined within it. These classes include Player, Card, and Deck.
When a game is complete, the player will be asked if they want to play again. The player should record how many games they have won in a row. Players that win the largest number of games in a row should have their names and scores recorded in a high scores file called highscores.txt. This file should only contain the top 5 high scoring players and should be sorted from highest to lowest score.
PSP Assignment 2 201801 Page 10 of 24

REQUIREMENTS
It is expected that your solution will include the use of:
The supplied game.py module. You must modify and complete this file and the function inside.
Functions (output_player, play_game, player_turn, dealer_turn, read_high_scores, get_high_score_index, insert_high_score, output_high_scores and write_high_scores) implemented adhering to the assignment specifications.
The supplied blackjack.py file and the classes and methods contained within. This is provided for you please DO NOT modify this file.
Well constructed while loops. (Marks will be lost if you use break statements in order to exit from loops).
Well constructed for loops. (Marks will be lost if you use break statements in order to exit from loops).
Appropriate if/elif/else statements.
Output that strictly adheres to the assignment specifications.
Good programming practice:
o Consistent commenting and code layout. You are to provide comments to describe: your details, program
description, all variable definitions, all functions, and every significant section of code. o Meaningful variable names.
Your solutions MAY make use of the following:
o Built-in functions including range(), input(), print(), open(), min(), max(), format(),
len(), int(), str().
o List methods including append(), pop(), insert().
o String methods including find(), split(), strip(), format().
o Concatenation (+) operator to create/build new strings.
o Comparison operators (==, !=, <, >, etc).
o Access to individual elements in a list or string with an index i.e. seq_name[index].
o Access to a sequence of elements in a list or string using slicing i.e. seq_name[start:stop:step] o Use of any of the functions you have written in part 1 of the assignment.
o Use of any classes and methods in blackjack.py.
Your solutions MUST NOT use:
o break, or continue statements o quit() or exit()
Please ensure that you use Python 3.4 or later in order to complete your assignments. Your programs MUST run using Python 3.4.
PSP Assignment 2 201801 Page 11 of 24

PLAYER METHOD SUMMARY
Player objects have a name, score and hand of cards. They also contain the following methods for accessing and modifying this information:
get_name(name) Returns the Players name
hit_me(Card)
Adds the argument Card to the Players hand. Cards should be drawn from a Deck object before being added to the Player using hit_me()
get_hand()
Returns a list containing all Cards in the Players hand. Each Card contains methods allowing you to get the
value, rank or suit of the Card. You will have to loop through each item in the list and print them out to get a summary of what is in the Players hand.
get_hand_value()
Returns the combined value of all Cards in the Players hand. Aces will be increased to a value of 11 if the
resulting value would be less than or equal to 21. Otherwise, Aces will have a value of 1. All other face cards including Jacks, Queens and Kings will contribute 10 to the total value. Number cards will contribute their number value.
reset_hand()
Removes all Cards from the Players hand.
is_bust()
Returns True if the hand value exceeds 21. Otherwise returns False.
get_score()
Returns the number of games the Player has won in a row.
win()
Adds 1 to the number of games the Player has won in a row.
lose()
Resets the number of games the Player has won in a row back to zero.
DECK METHOD SUMMARY
A Deck object contains 52 unique instances of the Card class. The Deck contains the following methods for accessing and modifying Cards and information:
reset()
Restores the Deck to have 52 cards sorted in numerical order. The Deck should be reset between games.
shuffle()
Randomizes the order of the Cards in the Deck. Whenever the Deck is reset, it should also be shuffled.
draw_card()
Removes and returns the top Card from the Deck. If the deck has been shuffled previously, this Card will be random. If the size of the Deck is 0, this will return None.
size()
Returns the number of Cards left in the Deck. Each time the draw_card() method is called, the size will decrease by 1.
CARD METHOD SUMMARY
A Card object contains a rank, suit and value. This class is immutable and should only be accessed from a Deck object. The Card class contains the following methods for accessing information:
get_value()
Return the number value of the Card from 1-10. Aces will return 1 even though they may be worth 11.
get_suit()
Returns the Cards suit. This could be either Spades, Hearts, Diamonds or Clubs.
get_rank()
Returns the Cards rank as a String. This could return Ace, Jack, Queen, King or a number from 2 10.
PSP Assignment 2 201801 Page 12 of 24

STAGES
It is recommended that you develop this part of the assignment in the suggested stages. Each stage is worth a portion of the marks. 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 1
You will need both the blackjack.py and game.py files for this assignment. These have been provided for you.
Find these in Moodle. Ensure that they are saved in the same folder as each other.
Test to ensure that this is working correctly by opening and running game.py. If this is working correctly, you should see the following output:
Welcome to Blackjack
Stage 2
Add code underneath the constructor for the dealer object. Take input for the players name by prompting the user, Enter your name: . While the name contains any space characters, print, ERROR Must only be 1 word and take input for the name using the same prompt. Modify the player constructor to take the input name as an argument.
Stage 3
Implement the output_player function to print the argument Players name and each card in their hand followed by the combined hand value. You will need to call the player methods player.get_name(), player.get_hand() and player.get_hand_value() to get this information. You may need to use a loop to get each card before printing them. You will need to print it in the form:
s hand: , ,
Total:
For example, if the Players name is Bob and their hand contains the Ace of Spades, 5 of Hearts and 10 of Diamonds, the output_player function would print:
Bobs hand: Ace of Spades, 5 of Hearts, 10 of Diamonds Total: 16
Test this function is working by passing both the player and dealer into the function as arguments. Remove this test code when you are sure it is working.
Stage 4
Implement the play_game function to shuffle the deck. It should then draw 2 cards from the Deck for both the player and dealer. Call the hit_me method to add a card to a Players hand. When both players have 2 cards, call the output_player function with both players as an argument. Test this is working by calling the play_game function with the player, dealer and deck as arguments. Run your code.
It should print something like this:
Welcome to Blackjack
Enter your name: Michael
Dealers hand: Ace of Spades, 6 of Spades
Total: 17
Michaels hand: 2 of Diamonds, 2 of Spades
Total: 4
PSP Assignment 2 201801
Page 13 of 24

Stage 5
In the main program, create a variable called play set to the string yes. While this is yes, call the play_game function. Inside the loop take input for the play variable by asking if the user, Would you like to play again (yes/no): . Add an error handling loop that ensures the user can only enter yes or no. If the user enters anything else, it should output, ERROR: Only enter yes or no’ and then ask for input again.
Running your code should produce output that looks like this:
Welcome to Blackjack
Enter your name: Bob Brown
ERROR Must only be 1 word
Enter your name: Michael
Dealers hand: 2 of Hearts, 5 of Spades
Total: 7
Michaels hand: 3 of Diamonds, 7 of Clubs
Total: 10
Would you like to play again (yes/no): y
ERROR: Only enter yes or no
Would you like to play again (yes/no): yes
Dealers hand: 2 of Hearts, 5 of Spades, Ace of Spades, 7 of Diamonds Total: 15
Michaels hand: 3 of Diamonds, 7 of Clubs, 9 of Diamonds, 6 of Hearts Total: 25
Would you like to play again (yes/no): no
Notice that the player hand is now 4 cards long. The Player hands should be reset between games. The Deck should also be reset and shuffled.
Stage 6
Implement the player_turn function so that it asks the user hit or stand? Add an error handling loop that ensures the user can only enter hit or stand. If the user enters anything else, it should output, ERROR: Only enter hit or stand’ and then ask for input again.
You should call the players is_bust method to find out if their hand value exceeds 21. While the player has not bust and the players choice is hit, the player should draw a card from the deck. It should then call the output_player function again to see the updated hand. If that card draw did not cause the player to bust, Ask the user to hit or stand? again, followed by the same error handling loop as before.
Call the player_turn function from the play_game function. If, after the player_turn, the player has bust, it should print, busts! It should also call the player lose method, so it sets their win streak score to zero. Otherwise, it is the dealers turn. Running your code should output something like this:
Welcome to Blackjack
Enter your name: Tiffany
Dealers hand: Queen of Clubs, 3 of Spades
Total: 13
Tiffanys hand: 7 of Clubs, 2 of Spades
Total: 9
hit or stand? hit
Tiffanys hand: 7 of Clubs, 2 of Spades, 9 of Spades
Total: 18
hit or stand? hit
Tiffanys hand: 7 of Clubs, 2 of Spades, 9 of Spades, 8 of Hearts Total: 26
Tiffany busts!
Would you like to play again (yes/no): no
PSP Assignment 2 201801 Page 14 of 24

Stage 7
Write code in the dealer_turn function so that it hits the dealer with a card with the dealer has not bust and while their hand value is less than 17. Call the output_player function with the dealer as an argument each time the dealer draws a card. You will need to call the get_hand_value method on the dealer object.
In the play_game function, after calling the player_turn function, if the player has not bust, it is the dealers turn. Call the dealer_turn function. After the dealers turn if the dealer has bust or the players hand value is greater than the dealers, then print wins! It should call the players win method to add 1 to their win streak score; otherwise, if the dealers hand value is greater than the players, print loses! and call the player lose method; otherwise, print Draw!
When the game is complete, remember to reset each players hand and reset the deck using the reset_hand method and reset method respectively. Make sure the deck is shuffled before the next game by calling the shuffle method. Running your code should output something like this:
Welcome to Blackjack
Enter your name: Abigail
Dealers hand: 8 of Diamonds, 10 of Clubs
Total: 18
Abigails hand: Ace of Hearts, King of Hearts
Total: 21
hit or stand? stand
Abigail wins!
Would you like to play again (yes/no): yes
Dealers hand: 4 of Clubs, 8 of Diamonds
Total: 12
Abigails hand: 5 of Diamonds, 8 of Spades
Total: 13
hit or stand? hit
Abigails hand: 5 of Diamonds, 8 of Spades, Ace of Diamonds
Total: 14
hit or stand? hit
Abigails hand: 5 of Diamonds, 8 of Spades, Ace of Diamonds, 2 of Spades
Total: 16
hit or stand? hit
Abigails hand: 5 of Diamonds, 8 of Spades, Ace of Diamonds, 2 of Spades, King of Spades
Total: 26
Abigail busts!
Would you like to play again (yes/no): yes
Dealers hand: Ace of Diamonds, 5 of Spades
Total: 16
Abigails hand: 4 of Spades, Ace of Diamonds
Total: 15
hit or stand? hit
Abigails hand: 4 of Spades, Ace of Diamonds, Queen of Diamonds
Total: 15
hit or stand? hit
Abigails hand: 4 of Spades, Ace of Diamonds, Queen of Diamonds, 4 of Hearts
Total: 19
hit or stand? stand
Dealers hand: Ace of Diamonds, 5 of Spades, 10 of Spades
Total: 16
Dealers hand: Ace of Diamonds, 5 of Spades, 10 of Spades, 9 of Hearts
Total: 25
Abigail wins!
Would you like to play again (yes/no): no
PSP Assignment 2 201801
Page 15 of 24

Stage 8
Implement the read_high_scores function so that it reads each line in the file located at the argument filename. You will need to call the open function to read the file. For each line, get the substring before the space character to find the players name and get the substring after the space character to find the players score. The name should be added to the argument names list. The score should be typecast to an int and added to the argument scores list. At the end of the function, close the file. You will need to call the append method to add to the lists. You do not need to return anything from this function. A list parameter is a reference to its argument. When a list is changed inside a function, these changes will be saved in global scope.
Add code to the output_high_scores function to loop through each index in the lists and prints, . Where name is each name in the list and score is each score in the list.
In the global main code, after the player has decided to stop playing, create an empty list called names and an empty list called scores. Invoke the read_high_scores function with highscores.txt and your two lists as arguments. Follow this with a call to the output_high_scores function. At the end of the game, you should see something like this:
Tiffany 3
Jack 2
Bill 0
Stage 9
Implement the get_high_score_index function so that it finds the first score in the scores list that is less than or equal to the score argument. It should return the index of that value. If it did not find a score that was less than the argument, and the length of the scores list is less than 5, it should return the length of the scores list. In all other cases, it should return -1.
Before calling output_high_scores in the main program, it should find the position that the players high score should be inserted into. Call the get_high_score_index method with the players score as an argument. You will need to call the get_score method to return this value. Test this by printing Player score is and INSERT AT . Ensure that after playing the game it prints the index of where your score should be added given that position 0 means it is the top score. Remove these prints statements when you are sure it is working.
Stage 10
Implement the insert_high_score function so that it inserts the argument name at the pos in the names list. It should also insert the argument score into the scores list at the pos. If the length of the names list is greater than 5, it should remove the last item in both the names and scores lists. In any case, it should print, New High Score!
In the global code, if the index returned from get_high_score_index is greater than -1, you should call the insert_high_score function with the correct arguments. If the output_high_scores function is called afterwards, the current players name and score should be added to the lists.
Stage 11
Implement the write_high_scores function so that it opens the file at the argument filename for writing. It should then loop through the first 5 positions in the names list and write each object in names followed by a space, then the object in the scores list at the same index, followed by a new line character. One line of the file could look like, Tony 3
. You may have to convert the score to a string before it can be written to file. After writing all the objects, remember to call the close method to save the file.
In your main code, after outputting the high scores, call the write_high_scores method. Then print, Goodbye. You may like to test this works by saving to a file called highscorestest.txt. When you believe it is working, change the file name to highscores.txt, so that it overwrites the highscores file each time you play the game.
Stage 12
Modify your output_high_scores function so that the high scores are formatted in a pretty table. The names should be left aligned within a field of 16 spaces. The scores should be right aligned within a field of 4 spaces. There should be vertical bars on the left and right sides. The top and bottom should be filled with dash characters, but the words, High Scores, should appear in the center of the top row of dashes. Check the section titled, Useful Built-in Python Functions for help with formatting text!
PSP Assignment 2 201801 Page 16 of 24

Stage 13
Finally, check the section titled Sample Output and, if necessary, modify your code so that:
The output produced by your program is formatted EXACTLY the same way as the sample output provided.
Your program behaves as described in these specifications and in the same way as the sample output.
SAMPLE OUTPUT
Sample output 1:
Welcome to Blackjack
Enter your name: Michael
Dealers hand: 8 of Spades, 9 of Clubs
Total: 17
Michaels hand: 7 of Spades, 7 of Hearts
Total: 14
hit or stand? hit
Michaels hand: 7 of Spades, 7 of Hearts, 7 of Diamonds
Total: 21
hit or stand? stand
Michael wins!
Would you like to play again (yes/no): no
New High Score!
| High Scores |
| Michael 1 |
| |
Sample output 2:
Welcome to Blackjack
Enter your name: Jackie
Dealers hand: 5 of Clubs, 2 of Spades
Total: 7
Jackies hand: 2 of Hearts, Jack of Spades
Total: 12
hit or stand? hit
Jackies hand: 2 of Hearts, Jack of Spades, 5 of Diamonds
Total: 17
hit or stand? hit
Jackies hand: 2 of Hearts, Jack of Spades, 5 of Diamonds, 6 of Spades
Total: 23
Jackie busts!
Would you like to play again (yes/no): no
New High Score!
| High Scores |
| Michael 1 |
| Jackie0 |
| |
Goodbye
Sample output 3:
Welcome to Blackjack
Enter your name: Sally
PSP Assignment 2 201801
Page 17 of 24

Dealers hand: 4 of Clubs, 6 of Diamonds
Total: 10
Sallys hand: 8 of Clubs, 3 of Hearts
Total: 11
hit or stand? hit
Sallys hand: 8 of Clubs, 3 of Hearts, Ace of Diamonds
Total: 12
hit or stand? hit
Sallys hand: 8 of Clubs, 3 of Hearts, Ace of Diamonds, Ace of Hearts
Total: 13
hit or stand? hit
Sallys hand: 8 of Clubs, 3 of Hearts, Ace of Diamonds, Ace of Hearts, Ace of Spades
Total: 14
hit or stand? hit
Sallys hand: 8 of Clubs, 3 of Hearts, Ace of Diamonds, Ace of Hearts, Ace of Spades, 4 of
Spades
Total: 18
hit or stand? stand
Dealers hand: 4 of Clubs, 6 of Diamonds, 8 of Hearts
Total: 18
Draw!
Would you like to play again (yes/no): yes
Dealers hand: 6 of Hearts, 5 of Clubs
Total: 11
Sallys hand: 10 of Hearts, 2 of Diamonds
Total: 12
hit or stand? hit
Sallys hand: 10 of Hearts, 2 of Diamonds, 7 of Hearts
Total: 19
hit or stand? stand
Dealers hand: 6 of Hearts, 5 of Clubs, 3 of Spades
Total: 14
Dealers hand: 6 of Hearts, 5 of Clubs, 3 of Spades, Ace of Clubs
Total: 15
Dealers hand: 6 of Hearts, 5 of Clubs, 3 of Spades, Ace of Clubs, Queen of Spades
Total: 25
Sally Wins!
Would you like to play again (yes/no): yes
Dealers hand: 5 of Clubs, 2 of Hearts
Total: 7
Sallys hand: Queen of Hearts, 9 of Hearts
Total: 19
hit or stand? stand
Dealers hand: 5 of Clubs, 2 of Hearts, 3 of Diamonds
Total: 10
Dealers hand: 5 of Clubs, 2 of Hearts, 3 of Diamonds, 3 of Clubs
Total: 13
Dealers hand: 5 of Clubs, 2 of Hearts, 3 of Diamonds, 3 of Clubs, 2 of Hearts
Total: 15
Dealers hand: 5 of Clubs, 2 of Hearts, 3 of Diamonds, 3 of Clubs, 2 of Hearts, 6 of Hearts
Total: 21
Sally Loses!
Would you like to play again (yes/no): no
New High Score!
| High Scores |
| Michael
| Jackie
| Sally
| |
Goodbye
PSP Assignment 2 201801
Page 18 of 24
1 | 0 | 0 |

Sample output 4:
Welcome to Blackjack
Enter your name: Norm Macdonald
ERROR Must only be 1 word
Enter your name: Billy Bob Thornton
ERROR Must only be 1 word
Enter your name: Norm
Dealers hand: 2 of Hearts, Jack of Diamonds
Total: 12
Norms hand: Queen of Spades, 3 of Clubs
Total: 13
hit or stand? stay
ERROR: Only enter hit or stand
hit or stand? stop
ERROR: Only enter hit or stand
hit or stand? quit
ERROR: Only enter hit or stand
hit or stand? hit
Norms hand: Queen of Spades, 3 of Clubs, King of Spades
Total: 23
Norm busts!
Would you like to play again (yes/no): y
ERROR: Only enter yes or no
Would you like to play again (yes/no): n
ERROR: Only enter yes or no
Would you like to play again (yes/no): yes
Dealers hand: 2 of Clubs, 4 of Clubs
Total: 6
Norms hand: Jack of Spades, 9 of Clubs
Total: 19
hit or stand? stand
Dealers hand: 2 of Clubs, 4 of Clubs, 6 of Spades
Total: 12
Dealers hand: 2 of Clubs, 4 of Clubs, 6 of Spades, 4 of Diamonds
Total: 16
Dealers hand: 2 of Clubs, 4 of Clubs, 6 of Spades, 4 of Diamonds, Ace of Clubs
Total: 17
Norm Wins!
Would you like to play again (yes/no): no
New High Score!
| High Scores |
| Michael
| Norm
| Jackie
| Sally
1 | 1 | 0 | 0 |
| | Goodbye
PSP Assignment 2 201801
Page 19 of 24

USEFUL BUILT-IN PYTHON FUNCTIONS Format Function:
You can use the format() function to format the way integers, floats and strings are displayed to the screen. In the following example: print(format(user_total, 10d))
The value assigned to variable user_total is printed in a field that is 10 spaces wide.
The number in the format string determines the width of the output field.
The letter in the format string determines the type of output you want to format:
There are other alignment options:
Option
Meaning
d
Decimal Integer
s
String
f
Floating Point Number
Option
Meaning
<‘ Forces the field to be left-aligned within the available space (this is the default for most objects).’>
Forces the field to be right-aligned within the available space (this is the default for numbers).
^
Forces the field to be centered within the available space.
Formatting Integers:
Examples of use:
>>> format(15, 10d)
15
>>> format(15, ^10d)
15
>>> format(15, <10d’)’15’>>> format(15, >10d)
15
Formatting Strings:
Examples of use:
>>> format(You, 10s)
You
>>> format(You, ^10s)
You
>>> format(You, <10s’)’You ‘>>> format(You, >10s)
You
Formatting Floats:
Examples of use:
>>> format(2.5, 10f)
2.500000
>>> format(2.5, ^10f)
2.500000
>>> format(2.5, <10f’)’2.500000′>>> format(2.5, >10f)
2.500000
>>> format(2.999, 10.5f)
2.99900
>>> format(2.999, 10.2f)
3.00
Other examples:
>>> print($, format(4, .2f), for a coffee, sep=, end=!) $4.00 for a coffee!
>>> print(*, format(You, <8s”), ‘|’, format(“Me”, “>8s), *, sep=-) *-You -|- Me-*
>>> print(*, format(You, >8s), |, format(Me, <8s”), ‘*’, sep=’-‘) *- You-|-Me -*>>> print((-+format(5, ^5d)+-)*5) 5 5 5 5 5
PSP Assignment 2 201801 Page 20 of 24

SUBMISSION DETAILS
Make sure your .py files are included in a zip file. The zip file should be called yourIdAss2.zip. For example: 503123Ass2.zip
Ensure that the following files are included in your submission:
list_function.py
list_function_test.py
blackjack.py
game.py
highscores.txt
All files that you submit must include the following comments.
#
# File: fileName.py
# Author: your name
# Id: your id
# Description: Assignment 2 place assignment description here # This is my own work as defined by EIBT
# 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.
Students may also be expected to explain parts of their assignment to the marking lecturer to show their full understanding of the work.
The assignment will be demonstrated (by you) and marked during your practical class in week 12. You are also required to submit the assignment via Moodle.
You MUST attend the allocated marking session in order to receive marks for the assignment.
If you do not attend the marking session your assignment may NOT be marked.
PSP Assignment 2 201801 Page 21 of 24

EXTENSIONS AND LATE SUBMISSIONS
There will be no extensions/late submissions for this course without one of the following exceptions:
1. A medical certificate is provided that has the timing and duration of the illness and an opinion on how much the students ability to perform has been compromised by the illness. Please note if this information is not provided the medical certificate WILL NOT BE ACCEPTED. Late assessment items will not be accepted unless a medical certificate is presented to the Course Coordinator. The certificate must be produced as soon as possible and must cover the dates during which the assessment was to be attempted. In the case where you have a valid medical certificate, the due date will be extended by the number of days stated on the certificate up to five working days.
2. An EIBT counsellor contacts the Course Coordinator on your behalf requesting an extension. Normally you would use this if you have events outside your control adversely affecting your course work.
3. Unexpected work commitments. In this case, you will need to attach a letter from your work supervisor with your application stating the impact on your ability to complete your assessment.
4. Military obligations with proof.
Applications for extensions must be lodged with the Course Coordinator before the due date of the assignment
Note: Equipment failure, loss of data, Heavy work commitments or late starting of the course are not sufficient grounds for an extension.
ACADEMIC MISCONDUCT
Deliberate academic misconduct, such as plagiarism, is subject to penalties. DO NOT share your code with others
DO NOT copy code found on the internet or from any other source
Information about Academic integrity can be found in the Policies and Procedures section of the EIBT website.
PSP Assignment 2 201801 Page 22 of 24

MARKING CRITERIA
NAME:
Problem Solving and Programming (COMP 1039) Assignment 2 Weighting: 15% Due: Week 12, 2018
OUTPUT
SPECIFICATION
MARK
MAX MARK
MOUNTAIN PART 1
length Test
List length: 7
List length: 0
to_string Test
List is: r, i, n, g, i, n, g
List is: r-i-n-g-i-n-g
List is:
count Test
2 0 0
find Test
3 -1
insert_value Test
[one, two,three,four, five, six] [p, i, t]
[s, p, i, t]
[s, p, i, t, s]
remove_value Test
[r, i,g]
[i, n, g]
[r, i, n]

length Test
List length: 6
to_string Test
List is: 1, 7, 2, 3, 7, 7
List is: 1 7 2 3 7 7
count Test
3
find Test
1
insert_value Test
[1, 2, 3, 4, 5, 6]
remove_value Test
[1, 4, 5, 6]
End Testing!
Correct output
Correct letters
Correct sep
Missing sep on last item
Correct output
Correct found index -1 on not found
Correct return Insert start Insert middle Insert end
Correct return Remove start Remove middle Remove end
Correct output
Correct output
Correct output
Correct output
Correct output
Correct output
Comment header containing: Academic integrity statement
Descriptive variable names Comments throughout code
No break or continue statements
Use of inbuilt functions other than range() and str() Use of list or string methods
[2 marks]
[2 marks] [1 mark] [1 mark]
[3 marks]
[2 marks] [1 mark]
[1 mark] [1 mark] [1 mark] [1 mark]
[1 mark] [1 mark] [1 mark] [1 mark]
[1 mark] [1 mark] [1 mark] [1 mark] [1 mark] [1 mark]
[1 mark]
[1 mark] [1 mark] [1 mark]
[-2 per function] [-3 per function]
30 MARKS
PSP Assignment 2 201801 Page 23 of 24

BLACKJACK PART 2
Welcome to Blackjack
Enter your name: Joanne
Dealers hand: Ace of Diamonds
Total: 21
Joannes hand: 8 of Hearts
Total: 18
hit or stand? hit
Joannes hand: 8 of Hearts
Total: 27
Joanne busts!
Would you like to play again
(yes/no): yes
Dealers hand: 3 of Clubs, 8
Total: 11
Joannes hand: 4 of Spades, 7
Total: 11
hit or stand? hit
Joannes hand: 4 of Spades, 7
Total: 21
hit or stand? stand
Dealers hand: 3 of Clubs, 8
Total: 14
Dealers hand: 3 of Clubs, 8
Total: 24
Joanne wins!
Would you like to play again
(yes/no): yes
Dealers hand: 5 of Diamonds
Total: 10
Joannes hand: 8 of Diamonds
Total: 19
hit or stand? stand
Dealers hand: 5 of Diamonds, 5
Total: 12
Dealers hand: 5 of Diamonds, 5
Total: 19
Draw!
Would you like to play again
(yes/no): no
New High Score!
| High Scores |
| Tiffany
| Joanne
| Norm
| Sally
3 | 1 | 1 | 0 |
| |
Goodbye
Welcome message Name input
Name error handling
2 cards Dealer 2 cards Player
Correct hit input Hit error handling
Correct Player Bust
Play again input
Play again error handling
Hands reset
Deck reset and shuffled
Correct stand
Correct dealer hit
Correct Dealer Bust Correct Player Win Correct Player Lose Points
Correct Player Draw
Correct play again No
Correct New High Score message
Correct high scores file read Correct high scores index Correct high scores insert Correct high scores output Correct high scores file write High Scores limited to len 5
No comment header containing: Academic integrity statement
Use of break and continue Classes not used
Avoiding function definitions
writing in global main instead
[1 mark] [1 mark] [1 mark]
[1 mark] [1 mark]
[1 mark] [1 mark]
[1 mark]
[1 mark] [1 mark]
[1 mark] [1 mark]
[1 mark] [1 mark] [1 mark] [1 mark] [1 mark]
[1 mark]
[1 mark] [1 mark]
[2 marks] [1 mark] [2 marks] [2 marks] [2 marks] [1 mark]
[-1 mark] [-1 mark]
No comments throughout code
Incorrect formatting [-1
per error] [-2 per use] [-5 per class] [-3 per function]
30 MARKS
COMMENTS:
TOTAL
60 MARKS
PSP Assignment 2 201801 Page 24 of 24

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] game python shell COMP 1039
$25