Implementing the card guessing game

Assignment Help Python Programming
Reference no: EM131825901 , Length: 8

IMPLEMENTING THE CARD GUESSING GAME

Task:

You are to implement (code in Python) a computer game as outlined in the following description. Use what you have learned in class, including functions, selection, repetition and lists. You should use any feedback that you received from Assignment 1 to improve your program flow.

NB: The game is slightly different than the original one. Please read the description carefully and note the changes. The following functionality items must be added to your program and weren't in the original planning assessment:
- Game loop so that the player can play more than one game; a game no longer has 10 rounds
- Betting system - amounts in multiples of 5, balance of $0 forces quit
- Error handling for incorrect user input
- Appropriate code comments (each function should have a comment describing its purpose)
- Display overall amount won or lost on exit
- Make use of constants for variables with values that do not change

Program Features:

You are to design a simple guessing game, played by one player against the computer.
When the program begins it will ask the user for their name, then welcome them to the Guessing Game. The game will then begin, displaying the player's current balance (which starts at $100). The player will be asked how much they want to bet, which must be a whole number no less than 1, multiple of 5 and no more than their balance.

Once their bet has been entered the game will randomly generate two numbers, one for the player and one for the computer (they can be equal). These numbers are to be whole numbers between 1 and 13 (representing cards: Ace, 2 -10, Jack, Queen, King).
The player will then be told the value of their card as both a number (if the value is between 2 and

10) and the name of the card (1 is an Ace, 11 is a Jack, 12 is a Queen, and 13 is a King). The player will then choose whether they think the computer's card will be higher or lower, by entering H or L. Upper and lower case must be accepted, but any other input will result in an error and being asked again. Once the player has chosen then the computer's card will be announced to the player.

If the player was correct they get double their bet back (e.g. started with 100, bet 10 (balance is 90), win 20 (balance is 110). If the player was wrong they lost their bet (e.g. started with 100, bet 10 (balance is 90)), and if the two cards are equal then it's a tie (e.g. started with 100, bet 10 (balance is 90), get 10 back (balance is 100)) and the next round starts.

Each game follows the same pattern:
- Display balance
- Take the bet
- Reveal player's card
- Get player's guess
- Reveal computer's card

- Reveal winning/losing message
- Update balance

After each round the player can choose to continue, or quit. If the player's balance hits zero then the game ends, as if they had chosen to quit.

Once the game ends a farewell message will be displayed, noting the final balance and whether or not the player won (or lost) money overall.

Implementation:
- Python file:
You are to divide your solution into functions, following the principles shown in class. These may involve one for each menu option (other than Quit) as well as functions for parts of the program (e.g. calculating the current player balance could be implemented as a function).

- Planning document:
You also need to provide an updated version of your previous planning document showing an algorithm in pseudocode for each function, being sure to clearly indicate input and output variables for each. This should be based on your submission for Assignment One, with appropriate changes being made for new functionality.

You may show your assignment to your tutor during practical time to get comments or suggestions. It is important to note that you can only get help from staff in practical time after your prac work is finished.

Reference no: EM131825901

Questions Cloud

Prospect theory challenges rational behavioral assumptions : Give three examples on how prospect theory challenges rational behavioral assumptions of the utility theory & What two factors should be considered
What is the annualized yield based on an annual effective : An investor buys a $500,000 par value T-bill with 180 days till maturity for $482,000. He plans to sell it after 30 days, and forecasts a selling price of $487
Describe the components of hr planning and technology : Describe the Components of HR Planning and Technology. Human Resources has faced and continues to face an assortment of changes within its own functions.
Determine the total dollar amount of your profit or loss : One year ago, you bought a call option on 200,000 euros with an expiration date of one year. Determine the total dollar amount of your profit or loss.
Implementing the card guessing game : CP5639 - IMPLEMENTING THE CARD GUESSING GAME - You are to implement (code in Python) a computer game as outlined in the description
How to wok out algebraic equations : I need some examples of how to wok out algebraic equations. For example: Suppose you deposit $2,374.00 into an account today. In 15.00 years
What rate of return would dependable insurance earn : What rate of return would Dependable Insurance earn if Frieda accepts their offer?
How the fed should respond to prevailing conditions : How the Fed Should Respond to Prevailing Conditions. Consider the existing economic conditions, including inflation and economic growth.
Find an example of a recent merger or acquisition : Find an example of a recent merger or acquisition (within the last 15 years). Identify the parties involved, and discuss the history and details of the deal

Reviews

len1825901

1/22/2018 1:32:31 AM

Limited (2 – 4) Poor (0 – 1) Exhibits aspects of satisfactory (left) and poor (right) Code submitted does not run, and required significant work to be runnable No comments, or all comments are unclear or incorrect. All variables are inconsistently used, and/or poorly named All functions are inappropriate or incorrectly used No names are valid or meaningful Many unnecessary inputs or outputs Some necessary inputs and outputs are incorrect Almost all branches identified are inappropriate or incorrectly used, or there is almost no use of branches All branches are inefficient or poorly designed Very few loops used are appropriate and correctly used, or almost no loops are used No (or very few) loops exit when appropriate

len1825901

1/22/2018 1:32:26 AM

Good (7 – 8) Satisfactory (5 – 6) Exhibits aspects of exemplary (left) and satisfactory (right) Any errors in code syntax are small (mistyped names, or functions). Most comments are correctly inserted and clear, but some comments are not. Most variables are correctly created and used Most names are clear and appropriate Most functions are appropriate and correctly used Most names are valid and meaningful Almost no unnecessary inputs or outputs All necessary inputs and outputs are correct Most branches identified are appropriate and correctly used Most branches are efficient and well designed Most loops used are appropriate and correctly used Most loops exit when appropriate

len1825901

1/22/2018 1:29:40 AM

Marking Scheme: Exemplary (9 – 10) Correct use of Python syntax No syntax errors that prevent the game running as required. Correct use of Python comments All comments are correctly inserted, clear, and appropriate Effective and correct use of variables in the implemented solution All variables are correctly used. All variable names are clear and meaningful No inappropriate use of global or constant variables. Effective and correct use of functions in the implemented solution Functions are all appropriate and correctly used All names are valid and meaningful No unnecessary inputs or outputs All necessary inputs and outputs are correct Effective and correct use of branches in the implemented solution. The branches identified are appropriate and correctly used All branches are efficient and well designed Effective and correct use of loops in the implemented solution. All loops used are appropriate and correctly used All loops exit when appropriate

len1825901

1/22/2018 1:29:27 AM

Hand in two files (named like: FirstnameLastnameA2) containing the following: • Python file (.py) • Planning document in Microsoft Word format (.docx) Submit your files by uploading them on LearnJCU under Assessment. Due: Submit your assignment by the date and time specified on LearnJCU. Submissions received after this date will incur late penalties as described in the subject outline.

len1825901

1/22/2018 1:29:18 AM

o Output ? Make your output display as close as possible to the given examples, especially formatting and layout. Use Python library to find out how to display tabs and other special characters using Python 3. Hints: • You may find a list variable useful for move choices • You’ll need the updated balance to be stored in main, for display when the user quits. This may need to be returned from a function. • Try to use pre-defined Python functions wherever possible (such as sort, total, len)

len1825901

1/22/2018 1:29:08 AM

o Comments: ? You will need to add at LEAST one comment for each function that you define, including main ? The comment should either be placed directly above or below the function header ? The comment should describe: (a) the purpose of the function, (b) any inputs and (c) any returned values ? Additional comments should be placed at any position where the functionality of the program may be unclear ? All code MUST be properly indented o Error handling: ? Note that menu choice and other character selection should handle upper and lower case letters. • Look into the upper() or lower() functions in Python ? You also must make sure that any functions that get input from the user do error checking to ensure that the input is within the expected range (greater than zero, etc). ? Validate for an empty player name, as well as a name that is made only of letters (does not include digits).

len1825901

1/22/2018 1:29:02 AM

• Coding standards: o Variables: ? Wherever possible, variables should be set at the top of the function ? Although Python does not use constants you may set variables to values that will remain the same for the life of the program. These should be named in all capital letters. • You should be able to modify these variables to adjust the various values of items such as WIN, LOSE, STARTING_BALANCE, etc. This is an important aspect of this assignment, so consider carefully how to use constants. Remember to use these variables everywhere you can. • You will need to decide the best position to place these variables. ? You should AVOID the use of global variables unless they are needed in multiple places in the application ? In other words, you should pass the values to any functions that need them • And any constants only needed in one function should be ONLY in that function

len1825901

1/22/2018 1:28:57 AM

• Coding standards: o Variables: ? Wherever possible, variables should be set at the top of the function ? Although Python does not use constants you may set variables to values that will remain the same for the life of the program. These should be named in all capital letters. • You should be able to modify these variables to adjust the various values of items such as WIN, LOSE, STARTING_BALANCE, etc. This is an important aspect of this assignment, so consider carefully how to use constants. Remember to use these variables everywhere you can. • You will need to decide the best position to place these variables. ? You should AVOID the use of global variables unless they are needed in multiple places in the application ? In other words, you should pass the values to any functions that need them • And any constants only needed in one function should be ONLY in that function

len1825901

1/22/2018 1:28:52 AM

In this assignment, you will be focusing on basic planning and implementation using selections, repetition, and functions. Lists may be used where they are feasible. Use the techniques and patterns that you have learned and seen demonstrated in class. • You are allowed to use the code that Flowgorithm generates as a base for your project, although you will need to make additions to it: o Flowgorithm does not create a main function, so you must do this at either the top or the bottom of your code o Flowgorithm generated code does not always follow the best practices we have shown in lectures and practicals. Ensure that you do.

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd