Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CP1401 2022 TR1 Supplementary Assignment

Task Simple Zoo Simulator:

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:

•   Same as assignment 1: Input, Processing and Output; Decision and Repetition structures

•   New in assignment 2: Functions; random numbers; Lists

Incredibly Important: This assignment must not be where you first learn about these topics. The subject is designed to systematically teach you these principles through the lectures (first), then the   practicals. You should have practised each programming concept/construct many times before you   start using it in your assignment. If you get to a point in your assignment where you're not sure about something, go back and find help in the subject teaching (not on the Internet). Remember: 100% of what you need to know to complete this assignment is taught in the subject.

Problem Description:

(Note: the sample output below should help explain and demonstrate all of the requirements.)

The Simple Zoo Simulator is a program that simulates a simple zoo for fun and profit. You have a list of animals, which each generate "income" according to their name length (as everyone knows, longer animal names mean higher profit at a zoo … but they cost more to buy). Each day when you wait, a    random "luck" value between 0-100 is generated, which determines how much income the animals    generate, but if you are unlucky, a random animal will escape. You can buy new animals with the       income you make, but you cannot have more than one of each animal (name).

The program starts with a welcome, some instructions and three animals. Then there's a repeating menu with the following four options:

•   (W)ait

o This simulates a day starting with luck between 0 and 100. If you get less than 33 (think about constants) then a random animal from your list will escape and be deleted from   the list. Animals are deleted before any income calculations.

Each animal generates an amount of income according to the formula: luck / 100  * name length

e.g., if luck is 70, a "Zebra" animal (5 characters) would generate 0.7 * 5 = 3.5 as an integer, so an income of 3.

•   (D)isplay animals

o This simply displays the animals in your zoo (or No animals.” if you have none).

•   (A)dd new animal

o You can only add animals you can afford. You can have infinite animals but you cannot have any with the same name as existing animals . New animal names cannot be          empty, so error-check and repeat for empty names.

When you input an animal, the name should be converted to title case (using Python's .title() string method), so if the user enters "HEARTy bass", it will become "Hearty Bass" (and would cost 11 income).

When you add an animal, the name length (cost) is deducted from your total income.

•   (Q)uit

o This will end the main menu (follow the menu pattern!) and show the final details     including the animals, the number of days simulated, the number of animals and the amount of income.

Animals in the list should always be in alphabetical sorted order, but only sort when you need to (when the list has changed).

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 Expectations:

1.  Make use of named constants as appropriate, e.g., for things that would otherwise be "magic numbers", like the maximum rainfall or low luck threshold. Remember the guidelines for          constants:https://github.com/CP1404/Starter/wiki/Programming-Patterns#constants

a.  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 low rain threshold 20 mm… and the instructions should correctly show this. That's what constants are for.

2.  You are expected to include two kinds of useful comments in each of your program:

a. Every function should have a """docstring""".

b.  Use # block comments for things that might reasonably need a comment.

c.  Do not include unnecessary or many comments as these are just "noise" and make  your program harder to read. See the subject teaching for how to properly write good comments:https://github.com/CP1404/Starter/wiki/Styles-and-Conventions#commenting

3. Error checking should follow our standard pattern:

https://github.com/CP1404/Starter/wiki/Programming-Patterns#error-checking

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

https://github.com/CP1401/Practicals/tree/master/prac_06#example

So… follow what you've been taught and feel confident that you're on the right track! ☺

4.  Follow what you’ve been taught about how to write menus, and know that (Q) should not be a separate option within the menu:https://github.com/CP1404/Starter/wiki/Programming-Patterns#menus

5. 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. Do not use global variables. Any use of global variables will result in a fail    mark for the functions category. Here are some possibilities for functions:

a.  displaying the animals is done the same way in multiple places

b.  adding an animal is a significant section

c.  getting an animal name looks very similar to the kind of thing we wrote functions for in the teaching (getting a valid string)

d.  simulating a day is a nice-sized section for its own function

e.  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

6. Sample output from the program is provided. Follow this to meet requirements, but you are allowed to be a 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            animals differently, or use different output text when an animal dies, but you could not add or   remove a menu option and you couldn't choose to not have animals die. Please ask if you are unsure.

a.  The sample output shows "1 animals". This is fine, but you are welcome to add the logic to make this "1 animal".

b.  There's a comma at the end of the animals display. This is also fine. You don't need to change it but you can if you want to.

We strongly 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 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 create a working menu using the pattern you've been taught. For each menu item, just print something (like " … add animal…").

3.  Choose one function at a time to implement. E.g., start with the function to display animals 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 adding an animal, ignore the error-checking to start with. Get it working properly, then add error-checking.

5.  When writing the function to simulate a day, start with just generating and displaying random luck, then add the calculation to determine animal income.

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 when luck is consistently low, change the maximum luck from 100 to a low number   like 30 temporarily (that's how we created the 2nd sample output). Want to test what happens  when you run out of animals? Change the starting list to one animal instead of three.

Don't waste time running your program many many many times to hopefully get the random scenario you want to test.

Journal:

A significant desired outcome for this subject is you learning to develop solutions to problems        systematically and thoughtfully. That is, we are not only interested in the final product but in your process and the lessons you have learned through your experience. To encourage you in learning the systematic problem-solving process, you will record your work experiences and insights in a    simple journal for this assignment submitted as a PDF file.

There are three parts to this journal:

1.  Assignment 1 Reflections and Lessons

2.  Work Entries

3.  Summary

Assignment 1 Reflections and Lessons:

Before you begin working on this assignment, take some time to reflect on what you learned about your process through assignment 1, including how you will make changes this time based on any

feedback you received. You could consider your previous reflection exercise from the practicals:

https://github.com/CP1401/Practicals/tree/master/prac_07#reflection

Work Entries:

Each time you work on the assignment, record an entry in your journal that includes:

•   Date and time you worked, including duration

•   What you worked on with simple details, enough that someone reading it would understand

•   Any difficulties you faced and how you overcame them

Please do not include multiple entries for tiny work sessions. If you did 7 minutes, took a break then came back and did 37.5 minutes… we don't need this level of detail – just include a single entry of  about 45 minutes. These entries can be quite short, but make sure your focus is on your process,  not your actual code/work.

Summary:

Summarise the lessons you learned about the problem-solving process (not about Python code) through doing this assignment. This is the most important part – where you reflect on your     process and show what you have learned. Did anything you considered or changed based on     assignment 1 reflection prove important or useful? How are you improving in terms of following a systematic development process? What would you differently next time?

Please note that the only reasonable way to write a journal is regularly, as you develop your solution. A journal that is completed at the end of the assignment after you've finished everything is not a        journal and will not aid your learning experience as much.

Here is a sample journal entry that shows a 'satisfactory' level:

03/06/2022, 8:30 9:30am

Work: Pseudocode for main function; nearly completed start and menu section.

Challenges: Took a few goes to remember how to deal with lists and functions in pseudocode (not Python). Checked the "Pseudocode Guide" and followed the examples, which helped.

Sample Output:

It should be clear which parts below are user input (not printed, but entered by the user. Notice that the menu handles uppercase and lowercase letters. Notice what happens in various situations and don’t make up different requirements not specified or shown here.

Welcome to the Simple Zoo Simulator.

Animals cost and generate income according to their name length (e.g., a Zebra costs 5). Each day, animals generate income based on luck. Sometimes they escape.

You can buy new animals with the income your zoo generates.

You start with these animals:

Antelope, Fox, Zebra,

After 0 days, you have 3 animals and your total income is 0.

(W)ait

(D)isplay animals

(A)dd new animal

(Q)uit

Choose: hello

Invalid choice.

After 0 days, you have 3 animals and your total income is 0.

(W)ait

(D)isplay animals

(A)dd new animal

(Q)uit

Choose: wait

Invalid choice.

After 0 days, you have 3 animals and your total income is 0.

(W)ait   (D)isplay (A)dd new (Q)uit   Choose: d Antelope,

animals

animal

Fox, Zebra,

After 0 days, you have 3 animals and (W)ait

(D)isplay animals

(A)dd new animal

(Q)uit

Choose: a

Animal name: emu

You can't afford Emu.

After 0 days, you have 3 animals and (W)ait

(D)isplay animals

(A)dd new animal

(Q)uit

Choose: a

your

your

total income is 0.

total income is 0.