Code a medium-sized console-based program

Assignment Help Programming Languages
Reference no: EM132661593

CP1401 Fundamentals of Problem Solving and Programming - James Cook University

Task - Run the Risk!

For this assessment, you are to plan and then code a medium-sized console-based program in Python 3. This assignment is designed to help you build skills using:
• As in assignment 1: Input, Processing and Output; Decision structures; Repetition structures
• New in assignment 2: Functions and random numbers; Lists
The assignment also includes a developer's journal - a document you complete as you plan and code your program to help you focus on and improve your process and become a better developer.

Problem Description:

Run the Risk is a game that's totally not about gambling... but rather about risking digital "cash" to win or lose based on random chance.
The program starts with a welcome, some instructions and $1000. Then there's a repeating menu with the following options:

• Play
o Pressing P (or p) plays a turn of the game where you can choose an amount of cash to risk between 0 and your current balance. You can then choose from 3 risk-reward levels, as shown in the sample output below. Notice the error checking looping on both the risk amount and the risk option. Notice also that we have explicitly taught how to handle errors like this using the error checking pattern:

You may also notice that we have written useful functions for getting valid inputs before.

• Instructions
o This prints the instructions for the program. Notice that the instructions references values like the percentages for chance and reward, and remember that we've taught you about using CONSTANTS in places where values appear more than once - like in print statements and in calculations.
• Display report
o This displays a report of all the results from the game so far (unless there are no results yet). You will need to use a list to store the results of each turn. Notice how the dollar values are formatted and line up neatly.
• Show statistics*
o *This option is a challenge and will be marked as a separate criterion. Please do it only after completing the rest of the program. This displays statistics about the turns, including, but not limited to, those in the sample output: minimum, maximum, percentages, and the results in sorted order. Notice that the normal report maintains its chronological sorting.
• Quit
o Choosing this option will end the main menu and then display the report again. Notice that you have been taught how to write menus and you know that (Q) should not be a separate option within the menu, but rather the quit condition with final actions coded outside the main menu loop.

The sample output below will help you understand the requirements in detail. Make sure you understand how the program should work (that's the "analysis" step in program development) before you plan it ("design" step), then code it ("implementation"). Don't forget to test your program thoroughly, comparing it to these requirements.

Coding Requirements and Suggestions:
• Make use of named constants as appropriate, e.g. for things that would otherwise be "magic numbers", like the chance and reward percentages. Remember the guidelines for constants: if you use a value more than once, it should probably be a constant, and if you have a constant then you must use it in all places that you reference that value.
o A very good way to test that you have used constants properly is that you should be able to change ONE value in ONE place to make the game have a 99% chance of getting the silly reward... and the instructions should correctly show this. That's what constants are for.
• You are expected to include two kinds of useful comments in each of your program:
o Every function should have a """docstring""". See the subject teaching (checkpoint
2) for how to properly write docstrings.
o Use # block comments for things that might reasonably need a comment. It is not acceptable to have zero block comments.

Do not include unnecessary or many comments as these are usually just "noise" and make your program harder to read.
• Functions should be used for sections of the program and repeated tasks as you have been taught. Follow the DRY (Don't Repeat Yourself) principle and consider turning repeated code into functions. Here are some possibilities for functions:
o displaying the report is done the same way in multiple places
o playing a turn is a significant section
o displaying the instructions might only be one print statement, but it's quite large, so turning this into a function makes the main function easier to read
o the main menu and one-off program behaviour (like the start and end) should all be part of the main function - again, like our examples and teaching

• You do not need to handle incorrect types, like the user entering "money!" as their risk value. Another issue you do not need to handle is near-zero amounts - values less than $0.01. For this assignment, you can just pretend that all values will be in whole cents.

• Sample output from the program is provided. You should ensure that your program mostly matches this and definitely does in terms of meeting the requirements. But you are allowed to be a bit creative and customise the interface as you wish. So, please understand - you can change small details that don't break the requirements, but if you change it substantially you may miss some of the required aspects and lose marks. E.g. you could display the gain/loss messages differently, or express your creativity in the instructions, but you could not change menu options and you could not choose to allow negative risk amounts. Please ask if you are unsure.

We suggest you work incrementally on these tasks: focus on completing small parts rather than trying to get everything working at once. This is called "iterative development" and is a very common way of working, even for the professionals. A suggested approach to this is described below.

1. Start with planning and pseudocode - this is important for your process as well as your journal (see below for details about recording your process in your journal).

2. Start coding with the main function and creating a working menu using the pattern you've been taught. For each menu item, just print something (like "... play...") as a placeholder.

3. Choose one function at a time to implement. E.g. start with the function to play a turn and get this working, then call the function from your main menu.

4. When you do a larger section that's a bit more complex, keep it simple first, then add complexity. E.g. when getting a risk amount, ignore the error-checking to start with. Get it working properly, then add error-checking.

5. When writing the function to play a turn, start with just generating and displaying a random number between 1 and 100... but notice this is never printed... so print it as a helpful debugging output until your function is working correctly, then remove the print statement.

6. When writing and testing code with randomness, you can encourage it towards what you want to test by modifying your constants or starting values. E.g. when you want to test what happens the user is successful with a (s)illy risk, change the constant from 5 to 99 to make sure they get it. Then change it back. Don't waste time running your program many many times to hopefully get the random scenario you want to test.

This is not an exhaustive list of thoughtful ways to iteratively develop the program. Hopefully you've paid attention to the examples and teaching to see how we develop programs step by step and you have learned and practised this approach.

Attachment:- Fundamentals of Problem Solving and Programming.rar

Reference no: EM132661593

Questions Cloud

Unit 4 Construction Practice & Management Assignment : UNIT 4 Construction Practice & Management Assignment Help and Solution, Higher National Certificate in Construction and the Built Environment - Assessment
Practices earned value management : Describe the personnel establishment that actively practices earned value management (EVM).
Choice alignment sections of research prospectus : You will turn your attention to the Problem Statement and Research Method Choice Alignment sections of the Research Prospectus Template.
Attention to advantages of cross-border transfer : Discuss why a company desirous of competing in foreign country markets needs to pay close attention to the advantages of the cross-border transfer
Code a medium-sized console-based program : You are to plan and then code a medium-sized console-based program in Python 3. This assignment is designed to help you build skills using
What would be great brand- or line-extension : Make a list of 3 of your favorite brands. What would be a great brand-, or line-extension that you would like to see developed as a new product?
Identify strategies for crm project implementation : Identify strategies for the CRM project implementation. Identify reasons contributing to the failure of the CRM implementation at Mashkin.
Can any firm beat amazon in the marketplace : Can any firm beat Amazon in the marketplace? If not, why not? If so, how can they best do so? How formidable a competitor is Google for Amazon?
Organizational behavior topics : What possible Organizational Behavior topics do you see in this story? Explain. What personality traits would be most needed for this type of work arrangement?

Reviews

Write a Review

Programming Languages Questions & Answers

  Create a client arraylist to process input records in main

Create a Client ArrayList to process input records in main(). Use a for loop to read in the information from client.txt. Create a class called Client, the Client class must contain attributes for Client name.

  Write a program that takes a list and returns a new list

Write a program (function!) that takes a list and returns a new list that contains all the elements of the first list minus all the duplicates.

  Write a program that lets the user play the game of rock

Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. When the program begins, the user is asked to seed the random number generator, and a random number in the range of 1 through 3 is generated

  How will security be implemented in the linux systems

How will security be implemented in the Linux systems-both workstations and servers? End users have expressed some concern about completing their day-to-day.

  Design a class named pet, which should have following fields

The type field holds the type of animal that is the pet. Example values are "Dog", "Cat", and "Bird".

  Show the total monthly cost of the expenses

Write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile:

  Void function to display in nicely formated way

Write a void function display_exer() that display in a nicely formated way the eat members of an exerclass object. Pass the object to the function by reference.

  Write program which lets user enter charge account number

Write the program which lets user enter a charge account number. The program must determine if number is valid by checking for it in following list.

  Program asks for number of shares-whole dollar portion price

Program asks for number of shares held, whole dollar portion of price, and fraction portion. fraction portion is to be input as two integer values, one for numerator and one for the denominator.

  Write script which declares and sets variable

Write the script which declares and sets a variable that's equal to total outstanding balance due. If that balance is greater than $10,000.00, the script must return the result set consisting of VendorName,

  Program to write variable declarations and function calls

Write a program whose main function is merely a collection of variable declarations and function calls. This program reads a text and outputs the letters, together with their counts.

  London underground fire at the kings cross underground

london underground fire at the kings cross underground station on 18 november 1987 a wooden escalator caught fire

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