辅导案例-COMP 1039

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top






















COMP 1039
Problem Solving and Programming


Programming Assignment 2


Prepared by
Jo Zucco
SAIBT Modifications
Andreas Jordan/Jane Emmett

August 2020


Page 2 of 20


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 implement a game of Steal or Deal and then extending the program to keep
a record of the players who achieve high scores while playing.

This assignment is an individual task that will require an individual submission. You will 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 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 Overview

There are two parts to this assignment:

Part I: Implement a game of Steal or Deal

You are required to write a Python program that allows a player to play a game of Steal or Deal against the
computer. The program will allow a player to play as many games of as they wish.

Part II: High scores player information
You are required to extend your Python program (from part I) that will keep a record of the players who achieve high
scores while playing. The program will allow players to play steal or deal against the computer and will maintain
information on high scoring players (using Lists). Player information will be stored in a text file that will be read in
when the program commences. Once the initial high scores data has been read in from the file, the program should
allow the user to interactively query and manipulate the high scores information as well as play steal or deal against
the computer. Please ensure that you read sections titled ’Part II specification’ below for further details.


Page 3 of 20
Steal or Deal Rules

Steal or Deal is based on the Prisoner Dilemma (Practical 8 – Part II)

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.

Two players compete in a simple game of choice. On each turn, both parties must decide whether to cooperate or
betray one another. If they both cooperate (share), they each receive coins. If they both betray (steal), nobody wins
anything. But if one betrays and the other cooperates, the betrayer receives coins, and their trusting opponent will
lose coins.

Write a program to simulate this game.
The user will compete against the computer, with the computer choosing to share or steal at random.
On each turn, confirm each player’s choice by displaying them to the screen; then evaluate and display the
resulting outcome.

Also display the current coin total of both user and computer at the end of each turn.
The game will last for 5 turns, after which a winner is declared and the user can choose whether or not to
start a new game.

Game play:

• To begin, the player and the computer each start with 20 coins.
• The user then chooses steal or deal
• The computer will choose steal or deal at random.
• If both the user and the computer choose deal, they each receive 20 coins.
• If one chooses deal and other other chooses steal.
The player that choses steal wins 30 coins, the other player loses 10 coins
• If both choose steal, they both get nothing.
• The game ends after a specified number of rounds or if either player ends up with 0 coins

House rules:
• The user or computer can not choose steal 3 times in a row. If they try – their choice will change to Deal.
Page 4 of 19
Part 1 Specification: Steal or Deal
You are required to write a program that plays the game of Steal or Deal.
Your are required to implement a Python program that contains the following functions:
• display_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 : stealdeal_3000.py
Author : Batman
Stud ID : 30000
This is my own work as defined by SAIBT’s Academic Misconduct Policy.
• get_computer_choice()
This function gets a random number 0,1 and returns a string “STEAL” or “DEAL” based on the random number (0 for STEAL, 1 for
DEAL). It doesn’t take any parameters.
• get_user_choice()
This function prompts the user to enter a choice (S/s or D/d), validates that input and continues to ask until they enter S or D. It
then returns a string “STEAL” or “DEAL” based on the users choice.
• diplay_result(scores[], choices[])
This function takes in a 2 lists, one of both scores, and one of both choices. The first in each list represents
the playerScore/Choice, the second representing the computerScore/Choice and displays the current totals
in the format below. It does not return anything.
Player chooses STEAL
Computer chooses STEAL
Current Scores:
Player | Computer
-----------------
20 | 20
• play_game(numRounds)
This function will repeat the game numRounds times or until the computer or player gets 0.
It will return the players score
The parameter should have a default value of 5 (numRounds=5)
.
Page 5 of 19
PART 1 — Stages
The following stages of development are recommended:
Stage 1 – Setting Up
First download the zip file “Assignment2.zip” from the course website and extract its contents. You should see a folder
called 202002 PSP Assignment 2 with the following directory structure:
202002 PSP Assignment 2
Step 1: Rename stealdeal_yoursaibtid.py with your SAIBT ID and open the file in IDLE
You should see the following code
Step 2: Complete your display_details function and call as below
display_details()
Step 3: Run and test your file. You should see your relevant details in the format below
File : stealdeal_3000.py
Author : Batman
Stud ID : 30000
This is my own work as defined by SAIBT’s Academic Misconduct Policy.
Step 4: Back up a copy of your code as stealdeal_yourSAIBTID_P1S1.py.
It is important to save a copy of your code after every stage so you can easily go back to an earlier version if it is needed.

Stage 2 – Implement Function get_computer_choice()
Implement the function called get_computer_choice()– see description in Part 1 — Specification
Hint: you will need to import the random library (import random)
Call the function and then use a simple print statement to display the computer choice to the screen as follows:
Sample output 1:
Computer: STEAL
Stage 3 – Implement Function get_user_choice()
Implement the function called get_user_choice()– see description in Part 1 — Specification
Hint: you will need to include a while loop to validate the input to ensure only S, D, s, d is entered.
Call the function and then use a simple print statement to display the computer choice to the screen as follows:
Sample output 1:
Please enter choice S|D: x
Invalid input. Please enter choice S|D: S
Player: STEAL
Page 6 of 19
Stage 4 – Implement function display_result()
Step 1: Create a list named score with 2 items set to 20
Step 2: Create another list named choices and add the user and computer choice to the list
Step 3: Create the function display_result, taking in these 2 lists and display the details in the format below
Player chooses STEAL
Computer chooses STEAL
Current Scores:
Player | Computer
-----------------
20 | 20
Step 4: Call the function to ensure it is working.
Stage 5 – Implement function play_game()
Step 1: Let’s start by playing 1 round.
Check who wins and update the scores list on the rules below.
• If both the user and the computer choose deal, they each receive 20 coins.
• If one chooses deal and other other chooses steal.
The player that choses steal wins 30 coins, the other player loses 10 coins
• If both choose steal, they both get nothing
Step 2: Add this code into the function play_game(numRounds)
• This function should take in a parameter for the number of rounds.
The parameter should have a default value of 5 (numRounds=5)
• Add code to play more than one round.
It should stop repeating if the user or player has a score of 0 (or less) or after numRounds rounds of the
game. It should then return the player score
• The function should return the playerScore
Step 3: Add code so that the computer and user can’t choose Steal 3 times in a row. If they do it should display the
following message.
Can’t steal 3 times in a row. Choice changed to DEAL
Step 4: Call the function to check it is working
Ensure you are calling the other functions in the appropriate place so the game works.
Page 7 of 19
Part 2 Specification — High Scores Information
Write a menu driven program called highscores_yourSAIBTId.py that will allow the user to enter commands
and process these commands until the quit command is entered. The program will keep a record of the players who
achieve high scores while playing steal or deal. The program will allow players to play steal or deal against the
computer and will maintain information on high scoring players (using Lists). Player information will be stored in a text
file that will be read in when the program commences. Once the initial high scores data has been read in from the file,
the program should allow the user to interactively query and manipulate the high scores information as well as play
steal or deal against the computer.
Input
When your program begins, it will read in player information from a file called high_scores.txt. This is a text file
that stores high score information relating to players. An example input file called high_scores.txt can be found
on the course website (under the Assessment tab). You may assume that all data is in the correct format. The name
of the player and his/her high score is stored on one line and are separated by the space character as seen below.
Zhang Ziyi 50
Fox Mulder 35
Dale Cooper 30
Buster Bluth 10
After the program has stored the data (using two Lists, one List to store the player names and the other List to store
the high scores), it will enter interactive mode as described in the following section.
Interactive Mode
Your program should enter an interactive mode after the player high score information has been read from the file.
The program will allow the user to enter commands and process these commands until the quit command is entered.
The following commands should be allowed:
Each time your program prompts for a command, it should display the list of available commands. See the sample
output (at the end of this handout) to ensure that you have the output format correct.
For example:
Please enter command [scores, search, play, quit]:
1. Scores:
Outputs the contents of the high scores Lists as seen below using the function display_high_scores()
*****************************************************
****************** STEAL OR DEAL ******************
****************** HIGH SCORES ******************
*****************************************************
* *
* Player Name Score *
*****************************************************
*---------------------------------------------------*
* Zhang Ziyi 50 *
*---------------------------------------------------*
* Fox Mulder 35 *
*---------------------------------------------------*
* Dale Cooper 30 *
*---------------------------------------------------*
* Buster Bluth 10 *
*---------------------------------------------------*
* ???????? 0 *
*---------------------------------------------------*
*****************************************************
Page 8 of 19
2. Search:
Prompts for and reads the player’s name and searches for the player in the player names (high scores) list. If
the player is found in the player names (high scores) list, the player’s name, and high score, are displayed to
the screen as seen below
Dale Cooper has a high score of 6
If the player is not found in the high scores list, an error message stating the player has not been found is
displayed.
Billy Zane does not have a high scores entry.
3. Play:
Allows a player to play steal or deal against the computer until he/she does not wish to continue playing (enters
‘n’ when prompted to ‘Play again [y|n]?’). After every game, the player’s highest score is updated.
Once the player enters ‘n’ (i.e. does not wish to continue playing), it is determined whether the player has
qualified to be stored in the high scores list.
Congratulations! You have made it into the STEAL OR DEAL Hall of Fame!
If the player is to be added to the high scores list, the player’s name is prompted for and read:
Please enter your name: Dana Scully
The player’s information is then added to the high scores lists (player names and high scores lists). Player
information must be added to the high scores lists maintaining the sorted order of the lists (descending order of
total score). Where two players have the same total score, the new player should appear first. (Hint: to add a
record, shift all elements one position down the list).
A message should be displayed to the screen indicating they have been added to the high scores lists (player names
and high scores).
Successfully added Dana Scully to STEAL OR DEAL Hall of Fame.
If the player does not qualify for the high scores lists, a message should be displayed to the screen.
Sorry. You have not qualified for the STEAL OR DEAL Hall of Fame.
4. Quit:
Causes the program to quit, outputting the contents of the high scores lists (player names and player scores) to
a file (see section ‘Final Output’ below).
Final Output
When your program finishes (because you entered the quit command) your program should output the contents of
the high scores lists to a file called new_scores.txt. The format of this file should exactly match that of the input
file.
Page 9 of 19
Part 2 Practical Requirements — Highscores
It is recommended that you develop this part of the assignment in the suggested stages.
It is expected that your solution WILL include the use of:
• Your solution in a file called highscores_yourSAIBTId_.py.
• Appropriate and well constructed while and/or for loops. (Marks will be lost if you use break statements or
the like in order to exit from loops).
• You must use a loop in each function.
• Appropriate if, if-else, if-elif-else statements (as necessary).
• The following functions:
– read_file(filename, player_names, player_scores)
This function takes a file name and reads the contents of that file into the player_name and player_scores
lists passed as a parameter into the function. The function returns the number of players read in from the
file. You should make sure that you do not exceed the size of the lists (i.e. size of 5). The player_names
and player_scores lists should not exceed 5 elements. You must use a loop in your solution. You may
use String and/or List methods in this function.
– write_to_file(filename, player_names, player_scores, num_players)
This function will output the contents of the player_names and player_scores lists to a file in the same
format as the input file. The file will need to be opened for writing in this function (and of course closed
once all writing has been done). The function accepts the filename of the file to write to, the player_names
and player_scores lists and the number of players stored in the lists.
You must use a loop in your solution.
– display_high_scores(player_names, player_scores)
This function will take the player_names list and the player_scores list as parameters and will output the
contents of the lists to the screen. This function displays the information to the screen in the format
specified in the assignment specifications under the section - ’Screen Format’.
You must use a loop in your solution.
– find_player(player_names, name, num_players)
This function will take the player’s name as input along with the player_names list and the number of
players stored in the list and will return the position (index) of the player found in the player_names list. If
more than one player exists with the same name, return the position of the player who has the highest
score (i.e. first match found). If the player is not found, the function returns -1. You must use a loop in
your solution. You must not use list methods in your solution.
– is_high_score(player_scores, new_score)
This function takes a player’s score, and the player_scores list as input and determines whether the player
is to be added to the high scores lists (player_names and player_scores). If the player is to be added, the
insertion position is returned from this function. If the player does not qualify to have their name recorded
in the high scores lists, the function returns -1. You must use a loop in your solution.
– add_player(player_names, player_scores, new_name, new_score,
insert_position, num_players)
This function takes the high scores lists (player_names and player_scores), the player’s name and score,
the number of high scores (stored in the lists) and the position to insert the player into the lists. The
Page 10 of 19
player is added to the high scores lists at the insert position. The high scores lists (player_names and
player_scores) must be maintained in descending order of total score. Where two players have the same
total score, the new player being added should appear first. (Hint: when inserting a player, simply shift all
elements one position down the lists. You must make sure you are not exceeding list bounds and that your
lists do not contain more than five elements). The function returns the number of high scores stored in the
lists. You must use a loop in your solution. You must not use list methods in your solution.

– play_sod()
The play_sod() function allows a player to play steal or deal against the computer until he/she does
not wish to continue playing (enters ‘n’ when prompted to ‘Play again [y|n]?’).
After every game, the player’s total game score is checked to see if it is higher than previous games. This
function keeps the maximum score returned from function play_game()
You must use a loop in your solution.
• Good programming practice:
– Consistent commenting, layout and indentation. You are to provide comments to describe: your details,
program description, all variable definitions, all function definitions and every significant section of code.
– Meaningful variable names.

Your solutions MAY make use of the following:
• Built-in functions int(), input(), print(), range(), open(), len(), format() and str().
• Concatenation (+) operator to create/build new strings.
• Access the individual elements in a string with an index (one element only). i.e. string_name[index].
• Access the individual elements in a list with an index (one element only). i.e. list_name[index].

Your solutions MUST NOT use:
• Built-in functions (other than the int(), input(), print(), range(), open(), len(), format() and str() functions).
• Slice expressions to select a range of elements from a string or list. i.e. name[start:end].
• String or list methods (i.e. list_name.append(item), etc) (unless specified)
• Global variables as described in week 9 lecture.
• Do not use break, return or continue statements (or any other technique to break out of loops) in your
solution – 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 assignment
specifications. 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.

Your programs MUST run using Python 3.6.5 (or most current version).
Page 11 of 19

Part 2 — 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

To begin, download the provided file (available on the course website called highscores.py) and name it
highscores_yoursaibtit.py Define two lists (with five elements each) in order to store high score
information, that is, player names and their corresponding scores.

For example:
player_names = ["","","","",""]
player_scores = [0,0,0,0,0]

Stage 2

Call function play_game()

• Import the stealordeal module and call function play_game() as seen below.
• import stealordeal_yoursaibtid
• score = stealordeal_yoursaibtid.play_game()
• print(’Score is:’, score)

Stage 3

Write the code for function read_file() and display_high_scores() as specified in Part 2
Practical Requirements — Highscores Add code to call these two functions to ensure they are working
correctly.

Hint on reading files. . . : Week 8 contains the slides that discuss and demonstrate reading
in a file. You may want to refresh your memory by (re-)reading the relevant slides.
Hint on Testing. . . : After reading in the contents of the file, use a print
statement to print out the lists player_names and player_scores. They
should appear as follows:
[’Zhang Ziyi’, ‘Fox Mulder’, ‘Dale Cooper’, ‘Buster Bluth’, ’’]
[’50’, ’35’, ’30’, ’10’, 0]
Hint on formatting output. . . : The format command helps you to place text
either left, right or center aligned within a number of spaces that you can specify.

See the format command in IDLE Help.

Page 12 of 19
Output for function display_high_scores()
*****************************************************
****************** STEAL OR DEAL ******************
****************** HIGH SCORES ******************
*****************************************************
*---------------------------------------------------*
* Player Name Score *
*****************************************************
*---------------------------------------------------*
* Zhang Ziyi 50 *
*---------------------------------------------------*
* Fox Mulder 35 *
*---------------------------------------------------*
* Dale Cooper 30 *
*---------------------------------------------------*
* Buster Bluth 10 *
*---------------------------------------------------*
* ???????? 0 *
*---------------------------------------------------*
*****************************************************
Let’s look at how you can use the format command to display one of the lines above. . .
The following line is made up of 2 asterisks with a whole bunch of dashes:
*---------------------------------------------------*
Instead of manually counting the number of dashes you can use the len() function to tell you how many there are.
Step 1: Copy and paste the dashes into a Python Shell :)

>>>len(’ -------------------------------------------------- ’)

Step 2: Then use the repetition operator to display that many. For example:

print(’-’*20)

. . . will produce the following output:

>>>--------------------

Step 3: To add the asterisks (i.e. ‘*’) in the same print statement is just a matter of including them like so:

print(’*’, ’-’*numberOfDashes,’*’)


Don’t forget that when you have multiple items in a print statement, the default separator is a
space character. So either factor this in or simply change the default value to an empty string ;)

Page 13 of 19

Stage 4

Now that you know the information is being correctly stored in your high scores lists (player_names and player_scores
lists), write the code for function write_to_file(). Add code to call this function to ensure it is working correctly.

Just remember that while testing, where you call this function does not really matter. However you will
need to move the call to write_to_file() after developing your program.


Stage 5
Implement the interactive mode, i.e. to prompt for and read menu commands. Set up a loop to obtain and process
commands. Test to ensure that this is working correctly before moving onto the next stage. You do not need to call
any functions at this point, you may simply display an appropriate message to the screen, for example:

Sample output:
Please enter command [scores, search, play, quit]: roger
Not a valid command - please try again.
Please enter command [scores, search, play, quit]: scores
In scores command
Please enter command [scores, search, play, quit]: search
In search command
Please enter command [scores, search, play, quit]: play
In play command
Please enter command [scores, search, play, quit]: quit
Menu input should be validated with an appropriate message being displayed if incorrect input is entered by the user.



Stage 6

Implement one command at a time. Test to ensure the command is working correctly before starting the next com-
mand. Start with the quit and scores commands as they do not need you to add anything further to the file other
than ensuring that the function calls are in the correct place.
You should be able to see that for most commands there is a corresponding function(s).
For the remaining commands, the following implementation order is suggested:
• search command (find_player() function).
• play command (play_game(), is_high_score() and add_player() functions).


Page 14 of 19

Stage 7

Ensure that you have validated all user input with an appropriate message being displayed for incorrect input entered
by the user. Add code to validate all user input. Hint: use a while loop to validate input.

Stage 8

Finally, check the sample output (see section titled ‘Sample Output – Part II’ 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 the sample output provided.


Optional Challenge

Incorporate graphics to play the game – see Practical 7/8
Add further complexity/rules to the game


Submission Details
You are required to demonstrate your assignment to your practical supervisor during your week 12 class for
marking. The supervisor will mark your work using the marking criteria included in this document. You MUST
attend the practical session that you have been attending all study period in order to have your assignment
marked.

You are also required to submit an electronic copy of your program via Moodle. Assignments submitted to Moodle,
but not demonstrated during your allocated practical session, will NOT be marked. Likewise, assignments that have
been demonstrated during the practical session, but have not been submitted via Moodle, will NOT be marked.
Assignments are submitted to Moodle in order to check for plagiarism.
All students must follow the submission instructions below:
Ensure that your files are named correctly (as per instructions outlined in this document).

Ensure that the following files are included in your submission:

• stealdeal_yoursaibtid.py
• highscores_yoursaibtid.py.
For example (if your name is James Bond, your submission files would be as follows):
– stealdeal_33333.py
and
– highscores_33333.py
All files that you submit must include the following comments.
#
# File: fileName.py
# Author:your name
# SAIBT Id: yourSAIBTId
# Description: Assignment 1 - place assignment description here...
# This is my own work as defined by the University's
# Academic Misconduct policy.
Page 15 of 19
#

Assignments that do not contain these details may not be marked.

You must submit your program before the start of class and demonstrate your work to your marker. You will also be
required to demonstrate that you have correctly submitted your work to Moodle. Work that has not been correctly
submitted to Moodle will not be marked.

It is expected that students will make copies of all assignments and be able to provide these if required.
Page 16 of 19

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
student’s 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. A SAIBT 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 requested 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

Students are reminded that they should be aware of the academic misconduct guidelines available from the SAIBT
website (see https://www.saibt.sa.edu.au/policies).
Deliberate academic misconduct such as plagiarism is subject to penalties.
Page 17 of 19
MARKING CRITERIA


Problem Solving and Programming (COMP 1039)
Assignment 2 - Weighting: 15% - Due: Week 12, 2019
Name: Max Mark Mark Comment
Menu (Part 2):
Please enter command [scores, search, play, quit]:

2 Correct Prompt Validation

Scores Scores ***************************************************** ****************** STEAL OR DEAL ****************** ****************** HIGH SCORES ****************** ***************************************************** *---------------------------------------------------* * Player Name Score * ***************************************************** *---------------------------------------------------* * Zhang Ziyi 5 * *---------------------------------------------------* * Fox Mulder 4 * *---------------------------------------------------* * Dale Cooper 3 * *---------------------------------------------------* * Buster Bluth 1 * *---------------------------------------------------* * ???????? 0 * *---------------------------------------------------*
*****************************************************
8 Correct format Correct Info

Search
Please enter command [scores, search, play, quit]: search
Please enter player's name: Billy Zane
Billy Zane does not have a high scores entry.
Please enter command [scores, search, play, quit]: search
Please enter player's name: Zhang Ziyi Zhang Ziyi has a high score of 5
5 All output/prompts correct as per specifications



Play
Not a valid command - please try again.
Please enter y or n. Play again [y|n]?

Please enter choice S|D: x
Invalid input. Please enter choice S|D: D
Player chooses DEAL
Computer chooses STEAL
Current Scores:
Player | Computer
-----------------
20 | 30

15 Validation of user input

Updates scores

Displays scores in correct format

Game ends correctly


Displays final score

Displays highest score


Adds to high score in correct position

Displays confirmation message

Import of stealordeal.py
Output file (new
scores.txt)
5 output file exists and named new_scores.txt
correct results in file
correct format in file
Style:
Comments
▪ your details
▪ program description
▪ all variable definitions
▪ all functions
▪ code
Code layout and spacing
Meaningful variable names

Correct program design

Correct use of required functions


-10

-2 Insuffucient comments

-1 Inconsistent code layout/spacing
-2 Non-descriptive variable names

-2 If incorrect loop
-2 No or incorrect control structures
-2 Use of built-in functions not
allowed
-2 Use of slicking i.e. [::-1]
-2 Use of methods not allowed
-2 Use of global variables
-2 No validation of user input
-2 For using break/return/exit
statements to exit loops
Extension/Challenge

+ 5
Adds more complexity to game
Total 35
Page 18 of 19
Sample Output
Please enter command [scores, search, play, quit]: find
Not a valid command - please try again.
Please enter command [scores, search, play, quit]: scores


*****************************************************
****************** STEAL OR DEAL ******************
****************** HIGH SCORES ******************
*****************************************************
*---------------------------------------------------*
* Player Name Score *
*****************************************************
*---------------------------------------------------*
* Zhang Ziyi 50 *
*---------------------------------------------------*
* Fox Mulder 35 *
*---------------------------------------------------*
* Dale Cooper 30 *
*---------------------------------------------------*
* Buster Bluth 10 *
*---------------------------------------------------*
* ???????? 0 *
*---------------------------------------------------*
*****************************************************
Please enter command [scores, search, play, quit]: play

---------------------- START GAME ----------------------
Please enter choice S|D: x
Invalid input. Please enter choice S|D: D
Player chooses DEAL
Computer chooses STEAL
Current Scores:
Player | Computer
-----------------
20 | 30
Please enter choice S|D: D
Player chooses DEAL
Computer chooses DEAL
Current Scores:
Player | Computer
-----------------
40 | 40
Please enter choice S|D: S
Player chooses STEAL
Computer chooses DEAL
Current Scores:
Player | Computer
-----------------
70 | 30
Page 19 of 19
Please enter choice S|D: S
Player chooses STEAL
Computer chooses STEAL
Current Scores:
Player | Computer
-----------------
70 | 30
Please enter choice S|D: S
Can’t steal 3 times in a row. Choice changed to DEAL
Player chooses DEAL
Computer chooses STEAL
Current Scores:
Player | Computer
-----------------
60 | 60

----------------------- END GAME -----------------------

Your score: 60 - Play again [y|n]? p
Please enter y or n. Play again [y|n]? y

---------------------- START GAME ----------------------

Please enter choice S|D: D
Player chooses DEAL
Computer chooses STEAL
Current Scores:
Player | Computer
-----------------
10 | 50
Please enter choice S|D: D
Player chooses STEAL
Computer chooses STEAL
Current Scores:
Player | Computer
-----------------
0 | 80

----------------------- END GAME -----------------------

Your score: 0 - Play again [y|n]? n

Your highest score: 60

Congratulations! You have made it into the STEAL OR DEAL Hall of Fame!

Please enter your name: Dana Scully

Successfully added Dana Scully to STEAL OR DEAL Hall of Fame.


Please enter command [scores, search, play, quit]: scores

Page 20 of 19

*****************************************************
****************** STEAL OR DEAL ******************
****************** HIGH SCORES ******************
*****************************************************
*---------------------------------------------------*
* Player Name Score *
*****************************************************
*---------------------------------------------------*
* Dana Scully 60 *
*---------------------------------------------------*
* Zhang Ziyi 50 *
*---------------------------------------------------*
* Fox Mulder 35 *
*---------------------------------------------------*
* Dale Cooper 30 *
*---------------------------------------------------*
* Buster Bluth 10 *
*---------------------------------------------------*
*****************************************************
Please enter command [scores, search, play, quit]: search
Please enter name to search: Bob
Bob does not have a high scores entry.

Please enter command [scores, search, play, quit]: search
Please enter name to search: Dale Cooper
Dale Cooper has a high score of 30
Please enter command [scores, search, play, quit]: quit
Goodbye - thanks for playing!
Your program should output the following information to a file called new_scores.txt.
Dana Scully 60
Zhang Ziyi 50
Fox Mulder 35
Dale Cooper 30
Buster Bluth 10
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468