python
python copied to clipboard
[Function Arguments]: Add basic functions for Issue #2354
@BethanyG For issue #2354
I have started to work on the issue as I managed to get some free time, I have put some basic functions in, please review them and let me know about changes needed.
Hi & Welcome! 👋🏽 👋
Thank you for contributing to exercism/python 💛 💙 -- we really appreciate it! 🌟 🌈
This is an automated [🤖 🤖 ] comment for the maintainers of this repository, notifying them of your contribution. 🎉
Someone will review/reply to your changes shortly. (usually within 72 hours.)
You can safely ignore the maintainers section below.
⚠️ Please be aware ⚠️
This repo does not generally accept Pull Requests unless they follow our contributing guidelines and are:
1️⃣ Small, contained fixes for typos/grammar/punctuation/code syntax on [one] exercise, 2️⃣ Medium changes that have been agreed/discussed via a filed issue, 3️⃣ Contributions from our [help wanted][help-wanted] issue list, 4️⃣ Larger (previously agreed-upon) contributions from recent & regular (within the last 6 months) contributors.
Pull Requests not in these categories will be closed. 😞
💙 It looks like you are changing/adding files in a Concept Exercise! 💙
‼️ Did You...
|
✅️ Have You Checked:
|
. Are there any additional changes you need to make? Please make sure all associated files are present and consistent with your changes!
|
🛠️ Maintainers
Please take note 📒 of the following sections/review items 👀 ✨
🌈 Acknowledgements and Reputation
|
💫 General Code Quality
- [ ] The branch was updated & rebased with any (recent) upstream changes.
- [ ] All prose was checked for spelling and grammar.
- [ ] Files are formatted via yapf (yapf config) & conform to our coding standards
- [ ] Files pass flake8 with flake8 config & pylint with pylint config.
- [ ] Changed
example.py/exemplar.pyfiles still pass their associated test files. - [ ] Changed test files still work with associated
example.py/exemplar.pyfiles.- Check that tests fail properly, as well as succeed. (e.g., make some tests fail on purpose to "test the tests" & failure messages).
- [ ] All files have proper EOL.
- [ ] If a
JinJa2template was modified/created, was the test file regenerated?- Does the regenerated test file successfully test the exercises
example.pyfile?
- Does the regenerated test file successfully test the exercises
- [ ] The branch passes all CI checks &
configlet-lint.
Verify: |
🌿 Changes to Concept Exercises
- ❓ Are all required files still up-to-date & configured correctly for this change?_
- ❓ Does
<exercise>/.meta/design.mdneed to be updated with new implementation/design decisions - ❓ Do these changes require follow-on/supporting changes to related concept documents?
- [ ] Exercise
introduction.md- [ ] Do all code examples compile, run, and return the shown output?
- [ ] Are all the code examples formatted per the Python docs?
- [ ] Exercise
instructions.md - [ ] Exercise
hints.md - [ ] Check that exercise
design.mdwas fulfilled or edited appropriately - [ ] Exercise
exemplar.py- [ ] Only uses syntax previously introduced or explained.
- [ ] Is correct and appropriate for the exercise and story.
- [ ] Exercise
<exercise_name>.py(stub)- [ ] Includes appropriate docstrings and function names.
- [ ] Includes
passfor each function - [ ] Includes an EOL at the end
- [ ] Exercise
<exercise_name>_test.py- [ ] Tests cover all (reasonable) inputs and scenarios
- [ ] At least one test for each task in the exercise
- [ ] If using subtests or fixtures they're formatted correctly for the runner
- [ ] Classnames are
<ExerciseName>Test - [ ] Test functions are
test_<test_name>
- [ ] Exercise
config.json--> valid UUID4 - [ ] Corresponding concept
introduction.md - [ ] Corresponding concept
about.md - [ ] Concept
config.json - [ ] All Markdown Files : Prettier linting (for all markdown docs)
- [ ] All Code files: PyLint linting (except for test files)
- [ ] All files with text: Spell check & grammar review.
✨ Where applicable, check the following ✨
|
(as a reminder: Concept Exercise Anatomy) |
🚀 Changes to Practice Exercises
- [ ]
.docs/instructions.md(required)- Was this file updated and regenerated properly?
- [ ]
.docs/introduction.md(optional) - [ ]
.docs/introduction.append.md(optional) - [ ]
.docs/instructions.append.md(optional)- Are any additional instructions needed/provided? (e.g. error handling or information on classes)
- [ ]
.docs/hints.md(optional)- Was this file regenerated properly?
- [ ]
.meta/config.json(required) - [ ]
.meta/example.py(required)- Does this pass all the current tests as written/generated?
- [ ]
.meta/design.md(optional) - [ ]
.meta/template.j2(template for generating tests from canonical data)- Was a test file properly regenerated from this template?
- [ ]
.meta/tests.toml- Are there additional test cases to include or exclude?
- Are there any Python-specific test cases needed for this exercise?
- [ ]
<exercise-slug>_test.py- Does this file need to be regenerated?
- Does this file correctly test the
example.pyfile? - Does this file correctly report test failures and messages?
- [ ]
<exercise-slug>.py(required)- Does this stub have enough information to get the student started coding a valid solution?
|
Is the exercise is in line with Practice Exercise Anatomy? |
🐣 Brand-New Concept Exercises
- [ ] Exercise
introduction.md- [ ] Do all code examples compile, run, and return the shown output?
- [ ] Are all the code examples formatted per the Python docs?
- [ ] Exercise
instructions.md - [ ] Exercise
hints.md - [ ] Check that exercise
design.mdwas fulfilled or edited appropriately - [ ] Exercise
exemplar.py- [ ] Only uses syntax previously introduced or explained.
- [ ] Is correct and appropriate for the exercise and story.
- [ ] Exercise
<exercise_name>.py(stub)- [ ] Includes appropriate docstrings and function names.
- [ ] Includes
passfor each function - [ ] Includes an EOL at the end
- [ ] Exercise
<exercise_name>_test.py- [ ] Tests cover all (reasonable) inputs and scenarios
- [ ] At least one test for each task in the exercise
- [ ] If using subtests or fixtures they're formatted correctly for the runner
- [ ] Classnames are
<ExerciseName>Test - [ ] Test functions are
test_<test_name>
- [ ] Exercise
config.json--> valid UUID4 - [ ] Corresponding concept
introduction.md - [ ] Corresponding concept
about.md - [ ] Concept
config.json - [ ] All Markdown Files : Prettier linting (for all markdown docs)
- [ ] All Code files: Flake8 & PyLint linting
- [ ] All Code Examples: proper formatting and fencing. Verify they run in the REPL
- [ ] All files with text: Spell check & grammar review.
|
Is the exercise is in line with Concept Exercise Anatomy? |
Our 💖 for all your review efforts! 🌟 🦄
@asheeeshh - awesome news! I am a bit underwater with work at the moment, but will make sure to review & get you feedback by the end of the weekend. Apologies for the delay.
Here's what I came up with for functions. Still trying to think through how we'd handle the positional-only vs keyword-only stuff. Will post again if I think of something. Maybe producing a customer receipt with itemized and labeled items? 🤔
PRICING = {
"small_size_discount": .85,
"base_price": 200,
"tier_price": 170,
"time_to_bake_base": 40,
"time_to_bake_tier": 20,
"base_time_to_decorate": 15,
"tier_time_to_decorate": 5,
"customization_surcharge": 5,
"Chocolate Ganache Frosting": 55,
"Flavored Buttercream": 50,
"Flavored Whipped Cream": 40,
"Fruit Glaze": 30,
"Honey Glaze": 30,
"Flavored Custard": 30,
"Chocolate Ganache Filling": 50,
"Nuts Mixin": 40,
"Fruit Mixin": 50,
"Fruit Filling": 5,
"Jam Filling": 5,
"Berry Topping": 50,
"Sliced Fruit Topping": 40,
"Mixed Fruit Topping": 30,
"Nut Topping": 25
}
order= {"size": "15cm",
"Flavored Buttercream": "Blackberry",
"Flavored Custard": "Sesame",
"Fruit Mixin": "Melon",
"Berry Topping": "Blackberry"
}
def base_price(number_of_cakes, added_layers):
return (PRICING["base_price"] * number_of_cakes) + (PRICING["tier_price"] * added_layers)
# Positional with named/default values.
def time_for_baking_and_decorating(number_of_cakes, added_layers=0):
base_time = (number_of_cakes * PRICING["time_to_bake_base"]) + (number_of_cakes * PRICING["base_time_to_decorate"])
tier_time = (number_of_layers * PRICING["time_to_bake_tier"]) + (number_of_layers * PRICING["tier_time_to_decorate"])
return base_time + tier_time
# Positonal with arbitrary addon ingredients
def customization_price(cake_size="20cm", *addons):
added_price = sum(*addons)
return added_price * PRICING["small_size_discount"] if cake_size=="15cm" else added_price
# Positional with named(default) and arbitrary order dict.
def total_order_price(number_of_cakes, added_layers=0, **kwargs): # **kwargs method
base_cost = base_price(number_of_cakes, added_layers)
customizations = tuple((PRICING[item] for item in kwargs.keys() if item !="size"))
customization_cost = customization_price(kwargs["size"], customizations)
surcharge = 0 if added_layers < 2 else PRICING["customization_surcharge"]
return base_cost + customization_cost + surcharge
print(total_order_price(3, added_layers=4, **order))
>>>1438.0
Please feel free to adapt any of this, or ignore it if it doesn't fit with your ideas. I do think that you are on the right track. 😄 I'll see what I can come up with for the 5th task.
@asheeeshh - just checking in -- are you still wanting to work on this? Just let me know. Thanks!
@asheeeshh - just checking in -- are you still wanting to work on this? Just let me know. Thanks!
sorry for the late reply, but currently I'm a little too preoccupied with exams and stuff so I'm barely working on anything other than some personal projects, but I definitely want to complete this exercise, if I could be given some time I'll surely get back to it once I'm done with exams probably in last week of june.
@asheeeshh -- Thanks for checking in (and good luck with exams and term-end! 🌟 ). Right now, this exercise isn't blocking anything, so I am fine holding it for you. However, if that changes between now and the last week of June I will ping you and let you know. We may end up wanting to push this exercise out as a pre-requisite for another getting worked on. If that turns out to be the case, I will make sure that you both get credit for working on this and that we also find another suitable exercise for you to work on.
@BethanyG I'm not quite sure how we would implement positional only parameters, but keyword only parameters can be used to maybe display a list of all the extras like toppings which are added 🤔