Task – Market Garden 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:
• 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.
The Market Garden Simulator is a program that simulates the tranquil and refreshing activity of growing your own garden for fun and profit. You have a list of plants, which each generate “food”
according to their name length (as everyone knows, longer plant names mean higher profit at market… but they cost more to buy). Each day when you wait and watch, it rains a random amount.
This rainfall determines how much food the plants generate, but if you don’t get enough rain, a random plant will die. When you have enough food, you can spend some to buy new plants. To increase the biodiversity of your garden, you can’t buy plants you already have.
The program starts with a welcome, some instructions and four plants. Then there’s a repeating menu with the following four options (read the sample output to understand in more detail):
o This simulates a day starting with rainfall between 0 and 100mm (think about constants). If you get less than 30mm (did someone say think about constants?) then a random plant from your list will die (and be deleted from the list). Each plant generates an amount of food according to the formula:
(random value between 1/2 rainfall and actual rainfall) / 100 * length
e.g., if rainfall is 70, then a random value between 0.35 and 0.7 would multiply the length of each plant, so “Sage” plant (4 characters) would produce a result between
(0.35 and 0.7 * 4) 1.4 and 2.8 as an integer so 1 to 2, and “Thai Basil” (10 characters) would produce between 3 and 7.
• (D)isplay plants
o This simply displays the plants in your garden.
• (A)dd new plant
o You can only add plants you can afford. You can have an infinite number of plants.
New plant names cannot be blank; error-check and repeat for blank names.
Notice that we have explicitly taught how to handle errors like this using the error checking 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! J
Plant names should be converted to title case (using Python’s .title() string method), so if the user enters “thai BAsIL”, it will become “Thai Basil”.
If you already have the plant in your list, then you will be asked for the name again.
When you add a plant, the name length is deducted from your food
o This will end the main menu and show the final details including the plants, the number of days simulated, the number of plants and the amount of food.
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 loop condition with final actions coded outside the main menu loop: https://github.com/CP1404/Starter/wiki/Programming
The sample output below will help you understand these details. There is also a video demonstration available. 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 maximum rainfall or low rainfall threshold for plant death. 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.
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.
• 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 for how to properly write docstrings.
o Use # block comments for things that might reasonably need a comment.
Do not include unnecessary or many comments as these are 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 plants is done the same way in multiple places
o adding a plant is a significant section
o getting a plant name looks very similar to the kind of thing we wrote functions for in the teaching (getting a valid string)
o simulating a day is a nice-sized section for its own function
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 plant names that aren’t plants. It’s fine to have a “1401 Rocks” or “Is Monty Fun?” plant.
• 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 plants differently, or use different output text when a plant dies, but you could not add or remove a menu option and you couldn’t choose to not have plants die. Please ask if you are unsure.
• The sample output shows “1 plants”. This is fine, but you are welcome to add the logic to make this “1 plant”.
Also, there’s a comma at the end of the plants display. This is also fine and you don’t need to change it – but you can if you want to.
本网站支持 Alipay WeChatPay PayPal等支付方式
E-mail: firstname.lastname@example.org 微信号:vipnxx