Assignment title: Information
1 of 54
COMP 1039
Problem Solving and
Programming
Programming Assignment 1
Prepared by
Jo Zucco
School of Computer and Information Science
The University of South Australia
SAIBT and EIBT modifications
Jane Emmett and Rhys Moyne2 of 54
Contents
Introduction
Assignment Overview
Part I Specification
Practical Requirements (Part I)
Stages (Part I)
Sample Output – Part I
Bonus Work
Part II Specification
Practical Requirements (Part II)
Stages (Part II)
Sample Output – Part II
Submission Details
Academic Misconduct3 of 54
INTRODUCTION
This 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 the implementation of a game called Acey
Deucey and a simple encryption technique.
This assignment is an individual task that will require an individual submission. You will be required
to present your work to your lecturer in week 8. Important: You must attend the class that you have
been attending all semester 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: Acey Deucey
You are required to write a Python program that allows a player to play a game of Acey
Deucey. The program will allow a player to play as many games of Acey Deucey as they wish.
Once the player chooses to stop playing, the program will report a game summary to the
screen.
Part II: PSP Password Generator
You are required to write a Python program that does simple password generation including
encryption.4 of 54
PART I SPECIFICATION – ACEY DEUCEY
You are required to write a Python program called yourId_aceydeucey.py that allows a
player to play a game of Acey Deucey. The program will allow a player to play as many games
of Acey Deucey as they wish.
Acey Deucey Rules
Acey Deucey is a simple card game where a player is dealt two cards face-up. In order to play,
the player must first add an ante to the pot. The player then bets whether the third card drawn
will numerically fall in between the first two cards dealt. If the player wins (that is, the third card
numerically falls in between the first two cards), the player collects the bet amount from the pot.
If the player loses (that is, the third card falls outside of the first two cards), the player loses the
bet amount which is then placed in the pot. We will be simulating this card game with a humancontrolled player and a computer player.
http://en.wikipedia.org/wiki/Acey_Deucey_(card_game)
Although there are many variations of the rules and game play of Acey Deucey, we will
be adhering to the following rules and game play for the assignment.
Game play and rules:
The player and computer each start with $50. An amount of $10 is already in the pot.
The ante (the amount required to play) starts at $1 and doubles every five rounds.
To begin, the computer and player must add the ante into the pot.
The player begins first: two cards (a random number between 1 – 13) are displayed.
Before the next card is displayed, the player bets from nothing (zero) to the pot amount
or player's money based on what is smallest.
If the third card numerically falls in between the first two, the player wins. The player's
money is increased by the amount of money bet and the pot is reduced by the same
amount.
If the third card numerically falls outside of the first two cards, the player loses and the
player's money is decreased by the amount bet. This amount is added to the pot.
If the third card is the same as one of the first two cards, (for example: if the player has a
3 and 8, and the third card is another 3), the player has 'hit the post' and loses double
the bet amount from their current money. This amount is added the pot.
The computer plays in the same way as the player, randomly choosing a valid bet
amount (an amount smaller than the pot and money available).5 of 54
PRACTICAL REQUIREMENTS (PART I)
It is recommended that you develop this part of the assignment in the suggested stages. Each
stage is worth a portion of the marks.
It is expected that your solution will include the use of:
Your solution in a file called yourId_aceydeucey.py.
Appropriate and well constructed while and for loops. (Marks will be lost if you use
break statements in order to exit from loops).
Appropriate if, if-else, if-elif-else statements (as necessary).
The use of random.randint(1,13) function in order to simulate each card.
Output that strictly adheres to the assignment specifications. If you are not sure about
these details, you should check with the 'Sample Output – Part I' provided at the end of
this document.
Good programming practice:
Consistent commenting, layout and indentation. You are to provide comments to
describe: your details, program description, all variable definitions, and every significant
section of code.
Meaningful variable names.
NOTE: Do not use break, or continue statements 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 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.3.2 or later in order to complete your assignments.6 of 54
STAGES – (PART I)
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: Two cards
To begin, randomly generate two cards (1 – 13 inclusive).
Use random.randint()
Display the cards as seen below.
Sample output:
[PLAYER] Cards are:
_______ _______ _______
|7 | |? | |1 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______7| |______?| |______1|
Hint: Use the format() function to display 10, 11, 12 and 13 correctly.
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 2: Swap the cards
Write code that swaps the cards if the value of card 1 is greater than the value of card 2. This
will make it easier for the player to view and easier when it comes to testing whether the third
card falls in between the first two. For the example in Stage 1:
Sample output:
[PLAYER] Cards are:
_______ _______ _______
|1 | |? | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______1| |______?| |______7|7 of 54
Stage 3: Check two card values
Include code that checks whether the two cards have the same value. For this game, we need
them to be different. Your algorithm will look like:
Randomly generate two cards (1-13)
While the two cards are the same
o Randomly generate two cards (1-13)
Test your program to ensure that you never draw two cards that are the same.
Stage 4: Ask for a bet and draw the third card
Include code to ask the player for a bet and draw the third card - think about where this code
should go. For now, the maximum bet will always be $12. If the player enters a bet of $0,
display [PLAYER] PASS! and do not draw a third card.
Your output should match below.
Sample output 1:
[PLAYER] Cards are:
_______ _______ _______
|3 | |? | |J |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______3| |______?| |______J|
Enter bet (max $12): $5
_______ _______ _______
|3 | |10 | |J |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______3| |_____10| |______J|
Sample output 2:
[PLAYER] Cards are:
_______ _______ _______
|3 | |? | |J |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______3| |______?| |______J|8 of 54
Enter bet (max $12): $0
[PLAYER] PASS!
Stage 5: Check whether player wins or loses
Determine whether the player wins or loses and display the result to the screen - i.e. whether
the number on card three is in between the first two.
If the third card is in between the first two, the player wins the bet amount.
If the third card is outside of the first two, the player loses the bet amount.
If the third card is the same as one of the first two, (for example: the player has a 3 and
8, and the third card is 3), the player has 'hit the post' and loses double the bet amount.
Display an appropriate message as shown below:
Sample output 1:
[PLAYER] Cards are:
_______ _______ _______
|3 | |? | |J |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______3| |______?| |______J|
Enter bet (max $12): $5
_______ _______ _______
|3 | |10 | |J |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______3| |_____10| |______J|
[PLAYER] You win $5
Sample output 2:
[PLAYER] Cards are:
_______ _______ _______
|3 | |? | |4 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______3| |______?| |______4|9 of 54
Enter bet (max $12): $5
_______ _______ _______
|3 | |9 | |4 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______3| |______9| |______4|
[PLAYER] You lose $5
Sample output 3:
[PLAYER] Cards are:
_______ _______ _______
|A | |? | |2 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______A| |______?| |______2|
Enter bet (max $12): $5
_______ _______ _______
|A | |2 | |2 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______A| |______2| |______2|
[PLAYER] HIT THE POST!!!
[PLAYER] You lose $10
Stage 6: Modify your code for betting.
Define and initialize variable player_money to 50.
Define and initialize variable pot to 10.
Prompt the player to enter a bet. You need to ensure the maximum bet is the smallest
number between player_money and pot.
If the player wins, increase player_money by the bet and decrease the pot by the bet.
If the player loses, decrease player_money by the bet and increase the pot by the bet.
If the player hits the post, decrease player_money by double (2x) the bet and increase
the pot by double (2x) the bet.
Display player_money and pot to the screen.
Sample output 1:
Player: $50 Pot: $1010 of 54
[PLAYER] Cards are:
_______ _______ _______
|1 | |? | |2 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______1| |______?| |______2|
Enter bet (max $10): $5
_______ _______ _______
|1 | |2 | |2 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______1| |______2| |______2|
[PLAYER] HIT THE POST!!!
[PLAYER] You lose $10
Player: $40 Pot: $20
Sample output 2:
Player: $50 Pot: $10
[PLAYER] Cards are:
_______ _______ _______
|4 | |? | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______4| |______?| |______7|
Enter bet (max $10): $7
_______ _______ _______
|4 | |2 | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______4| |______2| |______7|11 of 54
[PLAYER] You lose $7
Player: $43 Pot: $17
Sample output 3:
Player: $50 Pot: $10
[PLAYER] Cards are:
_______ _______ _______
|2 | |? | |11 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______?| |_____11|
Enter bet (max $10): $10
_______ _______ _______
|2 | |4 | |11 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______4| |_____11|
[PLAYER] You win $10
Player: $60 Pot: $0
Stage 7: Ask to play and play again
Ask the user if they would like to play Acey Deucey
If they say yes - 'y', start the game.
If they say no - 'n', display a game summary.
Don't worry about validation now (e.g. if they don't enter y or n)
Sample output 1:
Player: $50 Pot: $10
Do you wish to play a round? (y/n)n
--- GAME SUMMARY ---
Player: $50 Pot: $10
Sample output 2:12 of 54
Player: $50 Pot: $10
Do you wish to play a round? (y/n)y
[PLAYER] Cards are:
_______ _______ _______
|4 | |? | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______4| |______?| |______7|
Enter bet (max $10): $7
_______ _______ _______
|4 | |2 | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______4| |______2| |______7|
[PLAYER] You lose $7
Player: $43 Pot: $17
Do you wish to play a round? (y/n)y
[PLAYER] Cards are:
_______ _______ _______
|2 | |? | |11 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______?| |_____11|
Enter bet (max $17): $10
_______ _______ _______
|2 | |4 | |11 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______4| |_____11|13 of 54
[PLAYER] You win $10
Player: $53 Pot: $7
Do you wish to play a round? (y/n)y
[PLAYER] Cards are:
_______ _______ _______
|1 | |? | |2 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______1| |______?| |______2|
Enter bet (max $7): $7
_______ _______ _______
|1 | |2 | |2 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______1| |______2| |______2|
[PLAYER] HIT THE POST!!!
[PLAYER] You lose $14
Player: $39 Pot: $21
Do you wish to play a round? (y/n)n
--- GAME SUMMARY ---
Player: $39 Pot: $21
Stage 8: Ante
Define and initialize variable ante to 1.
Display the ante at the beginning of each round
If the user wishes to play, subtract the ante from player_money and add ante to pot
Sample Output
Player: $50
Ante is: $1 Pot: $10
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
Player: $49
Ante is: $1 Pot: $1114 of 54
[PLAYER] Cards are:
_______ _______ _______
|4 | |? | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______4| |______?| |______7|
Enter bet (max $11): $7
_______ _______ _______
|4 | |2 | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______4| |______2| |______7|
[PLAYER] You lose $7
Player: $42
Ante is: $1 Pot: $18
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
Player: $41
Ante is: $1 Pot: $19
[PLAYER] Cards are:
_______ _______ _______
|2 | |? | |11 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______?| |_____11|
Enter bet (max $19): $10
_______ _______ _______
|2 | |4 | |11 |
| | | | | |
| | | | | |15 of 54
| | | | | |
| | | | | |
|______2| |______4| |_____11|
[PLAYER] You win $10
Player: $51
Ante is: $1 Pot: $9
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
Player: $50
Ante is: $1 Pot: $10
[PLAYER] Cards are:
_______ _______ _______
|1 | |? | |2 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______1| |______?| |______2|
Enter bet (max $10): $7
_______ _______ _______
|1 | |2 | |2 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______1| |______2| |______2|
[PLAYER] HIT THE POST!!!
[PLAYER] You lose $14
Player: $36
Ante is: $1 Pot: $24
Do you wish to play a round? (y/n)n
--- GAME SUMMARY ---
Player: $36
Ante: $1 Pot: $24
Stage 9: Game summary
Add code to keep track of how many games were played. Display this to the screen at the end
of the game
Sample Output16 of 54
--- GAME SUMMARY ---
Player: $50
Ante: $1 Pot: $10
You played 0 rounds.
Stage 10: Up the ante
Add code to double the ante after every five games.
Sample Output
Ante increase! It is now $2
Player: $35
Ante is: $2 Pot: $75
Stage 11: Add a computer player
Add a computer player. Define and initialise computer_money to 50. Make the computer add
an ante to the pot each round. The computer player should bet a random amount between the 0
and the minimum of pot amount and computer_money.
Hint: Copy your code for the human player and modify it slightly.
Sample Output
Player: $50 Computer: $50
Ante is: $1 Pot: $10
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $49 Computer: $49
Pot: $12
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|4 | |? | |7 |
| | | | | |
| | | | | |
| | | | | |17 of 54
| | | | | |
|______4| |______?| |______7|
Enter bet (max $12): $5
_______ _______ _______
|4 | |9 | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______4| |______9| |______7|
[PLAYER] You lose $5
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|10 | |? | |12 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_____10| |______?| |_____12|
PRESS to continue
Enter bet (max $17): $16
_______ _______ _______
|10 | |9 | |12 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_____10| |______9| |_____12|
[COMPUTER] You lose $16
PRESS to continue
Player: $44 Computer: $33
Ante is: $1 Pot: $3318 of 54
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $43 Computer: $32
Pot: $35
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|2 | |? | |11 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______?| |_____11|
Enter bet (max $35): $5
_______ _______ _______
|2 | |6 | |J |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______6| |______J|
[PLAYER] You win $5
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|2 | |? | |3 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______?| |______3|
PRESS to continue19 of 54
Enter bet (max $30): $18
_______ _______ _______
|2 | |3 | |3 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______3| |______3|
[COMPUTER] HIT THE POST!!!
[COMPUTER] You lose $36
PRESS to continue
Player: $48 Computer: $-4
Ante is: $1 Pot: $66
Do you wish to play a round? (y/n)n
Computer is broke! ($-4)
--- GAME SUMMARY ---
Player: $48 Computer: $-4
Ante: $1 Pot: $66
You played 2 rounds.
Stage 12: Add Instructions
Add a game menu and ask the player if they wish to see instructions for the game.
Sample Output
--- ACEY DEUCEY ---
Instructions? (y/n)y
Acey Deucey is a simple card game.
Two cards are drawn and the player places a bet on
whether the next card drawn will fall between the two cards.
You play against the computer, starting with $50.
Each round costs an ante of $1, which is doubled every
five rounds.
If you wish to pass, enter a bet of $0.20 of 54
However, you must still pay the ante.
Have fun!
Player: $50 Computer: $50
Ante is: $1 Pot: $10
Do you wish to play a round? (y/n)
Stage 13: Add code to validate all user input.
Use different while loops to check the user enters:
y or n when asked to play a round
bet value between 0 – (min of player_bet and pot)inclusive.
y or n when asked for instructions
If user enters an invalid command or amount, program should display messages as shown
below and prompt to enter again.
Sample output 1:
--- ACEY DEUCEY ---
Instructions? (y/n)j
Please enter 'y' or 'n'.
Instructions? (y/n)n
Do you wish to play a round? (y/n)j
Please enter 'y' or 'n'.
Do you wish to play a round? (y/n)
Enter bet (max $12): $500
You cannot bet more than the pot amount! ($12)
Enter bet (max $12): $20
You cannot bet more than the pot amount! ($12)
Stage 14: Check for Broke
Modify your code so that the game ends when player_money is less than or equal to zero.
Display Player is broke! ($0) before displaying the game summary. Also, if the
computer is broke, display Computer is broke! ($-4). In this case the computer will no
longer play, but the human player can continue playing. See the sample output section for more
information.
Sample Output
Player is broke! ($0)
Computer is broke! ($-3)
--- GAME SUMMARY ---
Player: $0 Computer: $-321 of 54
Ante: $2 Pot: $113
You played 7 rounds.
Stage 15: Check final output
See the sample output (see section titled 'Sample Output – Part I')
If needed, change 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.22 of 54
BONUS WORK - opportunity to challenge yourself…
Completion of this extra work will result in a bonus of up to 3 marks being added to your final mark for
this assignment. Note you can not get more than 100%
1. Make a more intelligent computer player. For example, add some rules that determine
when to bet and by how much (1 mark).
2. Introduce your own game variation – see the Wikipedia article
https://en.wikipedia.org/wiki/Acey_Deucey_(card_game) for ideas. (1 mark for a simple
variation, 2 marks for a more complicated variation)
3. Add code so that the 1 card is displayed as 'A' (for ace), the 11 as 'J' (for jack), the 12 as
'Q' (for queen) and the 12 as 'K' (for king). (1 mark)
4. Add code so that an actual deck of cards is simulated. After 52 draws, it will need to be
shuffled! (This allows card counting!) (2 marks)
5. Add code to keep track of card statistics. That is, how many times each card value was
generated. (1 mark)
Display this information to the screen after the game summary:
Sample Output 1:
Frequency
A
2 *
3
4 **
5 *
6 *
7
8 *
9 *
10 **
J Q
K
6. Modify your code to use appropriate functions (2 marks if implemented well).
You should note that you must have completed the basic assignment before attempting
this extension work. Bonus marks will only be awarded where the assignment already
performs and adheres to the assignment specifications above.
You must save and submit a version of the basic assignment. If your program does not
clearly demonstrate that you have the basic assignment working, then it is recommended that
you submit the earlier version that does demonstrate this. Code which is a starting point for
the bonus work but results in your program outputting something which does not clearly
demonstrate the basic assignment, will be given no bonus marks and score very poorly in the
basic assignment.
No further hints or guidance will be given on extension work.23 of 54
SAMPLE OUTPUT – PART I
Sample output 1:
--- ACEY DEUCEY ---
Instructions? (y/n)n
Player: $50 Computer: $50
Ante is: $1 Pot: $10
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $49 Computer: $49
Pot: $12
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|10 | |? | |12 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_____10| |______?| |_____12|
Enter bet (max $12): $5
_______ _______ _______
|10 | |K | |12 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_____10| |______K| |_____12|
[PLAYER] You lose $5
PRESS to continue
[COMPUTER] Cards are:24 of 54
_______ _______ _______
|8 | |? | |13 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______8| |______?| |_____13|
PRESS to continue
Enter bet (max $17): $13
_______ _______ _______
|8 | |3 | |13 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______8| |______3| |_____13|
[COMPUTER] You lose $13
PRESS to continue
Player: $44 Computer: $36
Ante is: $1 Pot: $30
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $43 Computer: $35
Pot: $32
PRESS to continue
[PLAYER] Cards are:25 of 54
_______ _______ _______
|5 | |? | |8 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______5| |______?| |______8|
Enter bet (max $32): $5
_______ _______ _______
|5 | |7 | |8 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______5| |______7| |______8|
[PLAYER] You win $5
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|9 | |? | |12 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______9| |______?| |_____12|
PRESS to continue
Enter bet (max $27): $21
_______ _______ _______
|9 | |7 | |12 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______9| |______7| |_____12|
[COMPUTER] You lose $21
PRESS to continue26 of 54
Player: $48 Computer: $14
Ante is: $1 Pot: $48
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $47 Computer: $13
Pot: $50
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|10 | |? | |13 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_____10| |______?| |_____13|
Enter bet (max $47): $5
_______ _______ _______
|10 | |Q | |13 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_____10| |______Q| |_____13|
[PLAYER] You win $5
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|6 | |? | |12 |
| | | | | |
| | | | | |27 of 54
| | | | | |
| | | | | |
|______6| |______?| |_____12|
PRESS to continue
Enter bet (max $13): $3
_______ _______ _______
|6 | |A | |12 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______6| |______A| |_____12|
[COMPUTER] You lose $3
PRESS to continue
Player: $52 Computer: $10
Ante is: $1 Pot: $48
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $51 Computer: $9
Pot: $50
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|8 | |? | |9 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |28 of 54
|______8| |______?| |______9|
Enter bet (max $50): $
Please enter a valid number.
Enter bet (max $50): $5
_______ _______ _______
|8 | |12 | |9 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______8| |_____12| |______9|
[PLAYER] You lose $5
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|2 | |? | |11 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______?| |_____11|
PRESS to continue
Enter bet (max $9): $3
_______ _______ _______
|2 | |9 | |11 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______9| |_____11|
[COMPUTER] You win $3
PRESS to continue
Player: $46 Computer: $12
Ante is: $1 Pot: $5229 of 54
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $45 Computer: $11
Pot: $54
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|3 | |? | |6 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______3| |______?| |______6|
Enter bet (max $45): $5
_______ _______ _______
|3 | |11 | |6 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______3| |_____11| |______6|
[PLAYER] You lose $5
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|10 | |? | |13 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_____10| |______?| |_____13|30 of 54
PRESS to continue
Enter bet (max $11): $6
_______ _______ _______
|10 | |7 | |K |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_____10| |______7| |______K|
[COMPUTER] You lose $6
PRESS to continue
Ante increase! It is now $2
Player: $40 Computer: $5
Ante is: $2 Pot: $65
Do you wish to play a round? (y/n)y
[PLAYER] Adds $2 to the pot.
[COMPUTER] Adds $2 to the pot.
Player: $38 Computer: $3
Pot: $69
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|J | |? | |K |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______J| |______?| |______K|
Enter bet (max $38): $531 of 54
_______ _______ _______
|J | |10 | |K |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______J| |_____10| |______K|
[PLAYER] You lose $5
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|8 | |? | |K |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______8| |______?| |______K|
PRESS to continue
Enter bet (max $3): $3
_______ _______ _______
|8 | |K | |K |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______8| |______K| |______K|
[COMPUTER] HIT THE POST!!!
[COMPUTER] You lose $6
PRESS to continue
Player: $33 Computer: $-3
Ante is: $2 Pot: $80
Do you wish to play a round? (y/n)y32 of 54
[PLAYER] Adds $2 to the pot.
Player: $31 Computer: $-3
Pot: $82
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|2 | |? | |10 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______?| |_____10|
Enter bet (max $31): $31
_______ _______ _______
|2 | |A | |10 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______A| |_____10|
[PLAYER] You lose $31
PRESS to continue
Computer is broke! ($-3)
Player is broke! ($0)
Computer is broke! ($-3)
--- GAME SUMMARY ---
Player: $0 Computer: $-3
Ante: $2 Pot: $113
You played 7 rounds.33 of 54
Sample output 2:
--- ACEY DEUCEY ---
Instructions? (y/n)n
Player: $50 Computer: $50
Ante is: $1 Pot: $10
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $49 Computer: $49
Pot: $12
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|5 | |? | |9 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______5| |______?| |______9|
Enter bet (max $12): $5
_______ _______ _______
|5 | |2 | |9 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______5| |______2| |______9|
[PLAYER] You lose $5
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|9 | |? | |10 |
| | | | | |
| | | | | |
| | | | | |34 of 54
| | | | | |
|______9| |______?| |_____10|
PRESS to continue
Enter bet (max $17): $14
_______ _______ _______
|9 | |9 | |10 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______9| |______9| |_____10|
[COMPUTER] HIT THE POST!!!
[COMPUTER] You lose $28
PRESS to continue
Player: $44 Computer: $21
Ante is: $1 Pot: $45
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $43 Computer: $20
Pot: $47
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|5 | |? | |11 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______5| |______?| |_____11|
Enter bet (max $43): $4335 of 54
_______ _______ _______
|5 | |4 | |11 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______5| |______4| |_____11|
[PLAYER] You lose $43
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|11 | |? | |13 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_____11| |______?| |_____13|
PRESS to continue
Enter bet (max $0): $14
_______ _______ _______
|11 | |12 | |13 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_____11| |_____12| |_____13|
[COMPUTER] You win $14
PRESS to continue
Player is broke! ($0)
--- GAME SUMMARY ---
Player: $0 Computer: $34
Ante: $1 Pot: $76
You played 2 rounds.
Sample output 3:
--- ACEY DEUCEY ---
Instructions? (y/n)y36 of 54
Acey Deucey is a simple card game.
Two cards are drawn and the player places a bet on
whether the next card drawn will fall between the two cards.
You play against the computer, starting with $50.
Each round costs an ante of $1, which is doubled every
five rounds.
If you wish to pass, enter a bet of $0.
However, you must still pay the ante.
Have fun!
Player: $50 Computer: $50
Ante is: $1 Pot: $10
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $49 Computer: $49
Pot: $12
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|3 | |? | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______3| |______?| |______7|
Enter bet (max $12): $0
[PLAYER] PASS!
PRESS to continue
[COMPUTER] Cards are:37 of 54
_______ _______ _______
|A | |? | |K |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______A| |______?| |______K|
PRESS to continue
Enter bet (max $12): $1
_______ _______ _______
|A | |4 | |K |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______A| |______4| |______K|
[COMPUTER] You win $1
PRESS to continue
Player: $49 Computer: $50
Ante is: $1 Pot: $11
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $48 Computer: $49
Pot: $13
PRESS to continue
[PLAYER] Cards are:38 of 54
_______ _______ _______
|J | |? | |K |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______J| |______?| |______K|
Enter bet (max $13): $0
[PLAYER] PASS!
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|2 | |? | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______?| |______7|
PRESS to continue
Enter bet (max $13): $9
_______ _______ _______
|2 | |3 | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______3| |______7|
[COMPUTER] You win $9
PRESS to continue
Player: $48 Computer: $58
Ante is: $1 Pot: $4
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.39 of 54
[COMPUTER] Adds $1 to the pot.
Player: $47 Computer: $57
Pot: $6
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|4 | |? | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______4| |______?| |______7|
Enter bet (max $6): $6
_______ _______ _______
|4 | |8 | |7 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______4| |______8| |______7|
[PLAYER] You lose $6
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|6 | |? | |9 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______6| |______?| |______9|
PRESS to continue
Enter bet (max $12): $1240 of 54
_______ _______ _______
|6 | |Q | |9 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______6| |______Q| |______9|
[COMPUTER] You lose $12
PRESS to continue
Player: $41 Computer: $45
Ante is: $1 Pot: $24
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $40 Computer: $44
Pot: $26
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|J | |? | |Q |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______J| |______?| |______Q|
Enter bet (max $26): $26
_______ _______ _______
|J | |10 | |Q |
| | | | | |
| | | | | |
| | | | | |41 of 54
| | | | | |
|______J| |_____10| |______Q|
[PLAYER] You lose $26
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______
|2 | |? | |3 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______?| |______3|
PRESS to continue
Enter bet (max $14): $38
_______ _______ _______
|2 | |9 | |3 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______2| |______9| |______3|
[COMPUTER] You lose $38
PRESS to continue
Player: $14 Computer: $6
Ante is: $1 Pot: $90
Do you wish to play a round? (y/n)n
--- GAME SUMMARY ---
Player: $14 Computer: $6
Ante: $1 Pot: $90
You played 4 rounds.42 of 54
Sample output 4:
--- ACEY DEUCEY ---
Instructions? (y/n)n
Player: $50 Computer: $50
Ante is: $1 Pot: $10
Do you wish to play a round? (y/n)n
--- GAME SUMMARY ---
Player: $50 Computer: $50
Ante: $1 Pot: $10
You played 0 rounds.
Sample output 5:
--- ACEY DEUCEY ---
Instructions? (y/n)n
Player: $50 Computer: $50
Ante is: $1 Pot: $10
Do you wish to play a round? (y/n)y
[PLAYER] Adds $1 to the pot.
[COMPUTER] Adds $1 to the pot.
Player: $49 Computer: $49
Pot: $12
PRESS to continue
[PLAYER] Cards are:
_______ _______ _______
|A | |? | |3 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______A| |______?| |______3|
Enter bet (max $12): $0
[PLAYER] PASS!
PRESS to continue
[COMPUTER] Cards are:
_______ _______ _______43 of 54
|4 | |? | |9 |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|______4| |______?| |______9|
PRESS to continue
Enter bet (max $12): $0
[COMPUTER] PASS!
PRESS to continue
Player: $49 Computer: $49
Ante is: $1 Pot: $12
Do you wish to play a round? (y/n)n
--- GAME SUMMARY ---
Player: $49 Computer: $49
Ante: $1 Pot: $12
You played 1 rounds.44 of 54
PART II SPECIFICATION – PSP PASSWORD GENERATOR
Write a Python program that generates passwords in three different ways.
1. Generate a random 6 character password. The first 3 characters must be capital letters (A – Z)
and the second 3 characters must be numeric characters (0 – 9).
2. Enter a secret word and then specify an amount of 'right shift' of the characters to encrypt
your word.
This simple method to encrypt data is attributed to Julius Caesar, the Roman Emperor. (If you
are interested, you may like to read the following… http://en.wikipedia.org/wiki/Caesar_cipher).
This method takes each character in a message and replaces it with one which is a certain
distance (offset) along the alphabet from it (moving right).
For example:
1 2 3 4 5 6 7 8 9 . . . . .
A B C D E F G H I J K L M . . .
+3
A B C D E F G H I J . . .
If the offset is 3 then A becomes D, B becomes E, C becomes F etc. In this case the word DIG
encrypts to GLJ. In order to decrypt the word/string, simply offset by the same amount moving
in the opposite direction (i.e. moving left).
Instead of restricting the cipher to the alphabetic characters only, we will use all of the printable
ASCII characters. That is, all the characters from ASCII 32 (Space) to ASCII 126 (~).
You will need to use the following two functions -
ord(c)
Given c, a string of length one ord(c), returns an integer representing the value of the string.
For example: ord('a') returns the integer 97.
chr(i)
Returns a string of one character whose ASCII code is the integer i.
For example: chr(97) returns the string 'a'.
3. Enter a secret sentence and create a password by taking the first letter of each
word.
4. Quit.
Write a menu driven program called yourSAIBTId_passwordGenerator.py that will allow
the user to enter commands and process these commands until the quit command is entered.45 of 54
PRACTICAL REQUIREMENTS (PART II)
It is recommended that you develop this part of the assignment in the suggested stages. Each stage is
worth a portion of the marks.
It is expected that your solution will include the use of:
Your solution in a file called yourSAIBTId_encryptor.py.
Appropriate and well constructed while and for loops. (Marks will be lost if you use break
statements in order to exit from loops).
Appropriate if, if-else, if-elif-else statements (as necessary).
The use of the ord() and chr() functions (as necessary).
Output that strictly adheres to the assignment specifications. If you are not sure about these
details, you should check with the 'Sample Output – Part II' provided at the end of this document.
Good programming practice:
o Consistent commenting, layout and indentation. You are to provide comments to describe:
your details, program description, all variable definitions, and every significant section of
code.
o Meaningful variable names.
NOTE: Do not use break, or continue statements 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
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 in order to complete your assignments. Your programs MUST run
using Python 3.46 of 54
STAGES (PART II)
The following stages of development are recommended. 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.
Stage 1: Create the menu
Set up a loop to obtain and process commands.
Test to ensure that this is working correctly before moving onto Stage 2.
You need not perform any password generation at this point, just display a message to the screen.
Sample output:
Welcome to the PSP Password Generator
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 1
In choice 1 - random password generation
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 2
In choice 2 - word encryption
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 3
In choice 3 - password generation from a sentence
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 4
Goodbye.47 of 54
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 2: Option 1 - Random password.
Generate a random password of 6 characters:
The first 3 characters must be capital letters (A – Z)
The second 3 characters must be numeric characters (0 – 9).
For example XAD325 or SDF189.
Sample output:
Welcome to the PSP Password Generator
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 1
Password: EBF170
*** Menu ***
1 Random
2 Encrypted word
3 From a sentence
4 Quit
Choose an option [1,2,3,4]: 4
Goodbye.
Stage 3: Option 2 – Encrypted word
Prompt for and read a word to be encrypted.
Prompt for and read the offset value (limited to a range of 1 to 94 inclusive).
Display the encrypted string to the screen.48 of 54
Please note: Your program must work with the printable ASCII character set.
That is, all the characters from ASCII 32 (Space) to ASCII 126 (~).
When the offset points to a character beyond 126 it should wrap around to the beginning of the set by
subtracting the total number of characters (95).
For example:
If the offset is 4 and the character is '}' (ASCII 125) then it will encrypt to ASCII 129. This is more
than 126 so it must wrap back to the beginning by subtracting the total number of characters (95).
This gives character 34.
Sample output:
Welcome to the PSP Password Generator
*** Menu ***
1 Random
2 Encrypted word
3 From a sentence
4 Quit
Choose an option [1,2,3,4]: 2
Enter a word to encrypt: Programming
Please enter offset value (1 to 94): 2
Password: Rtqitcookpi
*** Menu ***
1 Random
2 Encrypted word
3 From a sentence
4 Quit
Choose an option [1,2,3,4]: 4
Goodbye.49 of 54
Stage 4: Option 3 – Using a sentence
Prompt for and read a sentence.
Create a password by taking the first letter of each word.
For example for the sentence, "Hi, how are you.", the password is "Hhauy"
Sample output:
Welcome to the PSP Password Generator
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 3
Enter a sentence to encrypt (ending with .):
Once upon a time here were three bears.
Password: Ouattwtb
*** Menu ***
1 Random
2 Encrypted word
3 From a sentence
4 Quit
Choose an option [1,2,3,4]: 4
Goodbye.
Stage 5: Add code to validate all user input.
Include code to validate input for:
Menu: Inputs a number < 1 or > 4 at the menu
Encrypted: Enters an offset value (1 to 94)
Sentence: Enters a sentence ending in a '.'
If input is invalid print an error message (see sample output) and allow them to enter again.
Hint: use while loops
Sample output:
Welcome to the PSP Password Generator
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit50 of 54
Choose an option [1,2,3,4]: -1
Choice must be between 1 – 4 inclusive.
Choose an option [1,2,3,4]: 1
Password: EBF170
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 2
Enter a word to encrypt: Programming
Please enter offset value (1 to 94): 0
Invalid offset. Please enter offset value (1 to 94):2
Password: Rtqitcookpi
Choice must be between 1 – 4 inclusive.
Choose an option [1,2,3,4]: 3
Enter a sentence to encrypt (ending with .):
Once upon a time here were three
Invalid sentence. Enter a sentence to encrypt (ending with .):
Once upon a time here were three bears.
Password: Ouattwtb
Goodbye.
Stage 6: Check final sample output
See section titled 'Sample Output – Part II' towards the end of this document
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.51 of 54
SAMPLE OUTPUT – PART II
Sample output 1:
Welcome to the PSP Password Generator
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 1
Password: OIV124
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 3
Enter a sentence to encrypt (ending with .):
Once upon a time there were three bears.
Password: Ouattwtb
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 4
Goodbye.
Sample output 2:
Welcome to the PSP Password Generator
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 2
Enter a word to encrypt: Programming
Invalid offset. Please enter offset value (1 to 94): -1
Invalid offset. Please enter offset value (1 to 94): 100
Invalid offset. Please enter offset value (1 to 94):
Please enter offset value (1 to 94): 2
Password: Rtqitcookpi
*** Menu ***
1 Random
2 Encrypted word
3 Using a sentence
4 Quit
Choose an option [1,2,3,4]: 4
Goodbye.52 of 54
SUBMISSION DETAILS
Make sure your .py files are included in a zip file (WinZip). The zip file should be called yourIdAss1.zip.
For example: bonjy1402Ass1.zip
Ensure that the following files are included in your submission:
yourId_passwordGenerator.py
yourId_aceydeucey.py
For example:
bonjy1402_ passwordGenerator.py
bonjy1402_aceydeucey.py
If you have done the bonus work for Part 2 submit that as the file named
yourEmailId_aceydeucey_bonus.py as part of the zip file.
For example bonjy1402_aceydeucey_bonus.py.
All files that you submit must include the following comments.
# #
File: filename.py
# Author: your name
# Id: your id
# Version: 1.0 current date
# Description: Assignment 1 - ….
# This is my own work as defined by SAIBT
# 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.
The assignment will be demonstrated (by you) and marked during your practical class.
You are also required to submit the assignment via Moodle before your practical class
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 will NOT be marked.
Students may also be expected to explain parts of their assignment to the marking lecturer to
show their full understanding of the work.
LATE SUBMISSION
Late assignments will not be accepted unless a medical certificate (or appropriate supporting evidence)
is presented to the course coordinator no later than five working days after the deadline. The certificate
must be produced as soon as possible and must cover the dates during which the assignment 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. The assignment must be submitted
by the due time of that day.
ACADEMIC MISCONDUCT
Students are reminded that they should be aware of the academic misconduct guidelines available
from the SAIBT and EIBT websites.53 of 54
MARKING CRITERIA
More detail will be provided on a separate marking guide
Possible deductions:
Programming style: Things to watch for are poor or no commenting, poor variable names,
etc.
Submitted incorrectly: -10 marks if assignment is submitted incorrectly (i.e. not adhering to the
specs).
Assessment feedback
Problem Solving and Programming (COMP1039)
Assignment 1 - Weighting: 10%
NAME: MAX MARK COMMENT
PRODUCES CORRECT RESULTS (OUTPUT) –
PART I
10
-1 mark for each output displayed not
to
assignment specifications
ADHERES TO SPECIFICATIONS (CODE) – PART I
-2 marks for each code section not to
assignment specifications
PRODUCES CORRECT RESULTS (OUTPUT) –
PART II
10
-1 mark for each output displayed not
to
assignment specifications
ADHERES TO SPECIFICATIONS (CODE) – PART
II
-2 marks for each code section not to
assignment specifications
STYLE: Comments (your details,
description, all variable definitions & code),
code layout, meaningful variable names.
-2 insufficient comments
-2 inconsistent code layout
-2 non-descriptive variable names
TOTAL 20
The Graduate qualities being assessed by this assignment are indicated by an X:
x
GQ1: operate effectively with and upon a body of
knowledge x
GQ5: are committed to ethical action
and social responsibility
x GQ2: are prepared for lifelong learning GQ6: communicate effectively
x GQ3: are effective problem solvers x GQ7: demonstrate an international
perspective
x
GQ4:can work both autonomously and
collaboratively
This form meets the 2006 requirements of UniSA's Code of Good Practice: Student Assessment54 of 54
USEFUL BUILT-IN PYTHON FUNCTIONS – REQUIRED FOR PART I AND PART II
ord() and chr() Functions (useful for Part II):
ord(c)
Given c, a string of length one ord(c), returns an integer representing the value of the string.
For example: ord('a') returns the integer 97.
chr(i)
Returns a string of one character whose ASCII code is the integer i.
For example: chr(97) returns the string 'a'
Formatting Integers (useful for Part I):
You can use the format() function to format the way integers and strings are displayed to the screen.
In the following example, the value of total_user_score is printed in a field that is 10 spaces wide.
print(format(total_user_score, '10d'))
There are other alignment options as follows:
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.
More examples of use (including output):
>>> total_user_score = 100
>>> format(total_user_score, '10d')
' 100'
>>> format(total_user_score, '^10d')
' 100 '
>>> format(total_user_score, '<10d')
'100 '
>>> format(total_user_score, '>10d')
' 100'
This can be used inside a print function:
>>> print(format(total_user_score, '<10d'))
100
Formatting Text (aligning the text and specifying a width)
Examples of use, nested with the print function (including output):
>>> print(format("You", '10s'))
You
>>> print(format("You", '^10s'))
You
>>> print(format("You", '<10s'))
You
>>> print(format("You", '>10s'))
You