London | July SDC | Ali Qassab | Sprint 4 | Prep exercises#44
London | July SDC | Ali Qassab | Sprint 4 | Prep exercises#44AliQassab wants to merge 14 commits intoCodeYourFuture:mainfrom
Conversation
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
1 similar comment
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
LonMcGregor
left a comment
There was a problem hiding this comment.
Good start on this sprint's tasks, I have spotted a few areas where you could improve code further
prep-exercises/why_we_use_types.py
Outdated
| def double_bug(number): | ||
| return number * 3 | ||
|
|
||
| print(double_bug(10)) # Should return 20 but returns 30 No newline at end of file |
There was a problem hiding this comment.
can you think of any change you could make to this function to fix the bug?
There was a problem hiding this comment.
Change number * 3 to number * 2 so the function doubles the input.
|
|
||
| # This function will error at runtime if called | ||
| def get_address(person: Person) -> str: | ||
| return person.address # Error: Person has no attribute 'address' |
There was a problem hiding this comment.
Could you suggest a change that would fix this error?
There was a problem hiding this comment.
Add an address parameter to the Person class init and stored it as self.address
| self.DoB = DoB | ||
| self.preferred_operating_system = preferred_operating_system | ||
|
|
||
| def is_adult(self) -> bool: |
There was a problem hiding this comment.
What is a benefit or drawback of writing the function this way?
There was a problem hiding this comment.
Stores DoB (fixed), not age (changes over time), so is_adult() stays correct.
Rtores DoB (fixed), not age (changes over time), so is_adult() stays correct.
prep-exercises/generics.py
Outdated
| @dataclass(frozen=True) | ||
| class Person: | ||
| name: str | ||
| age: int |
There was a problem hiding this comment.
Can you solve this in a way that it always prints the current age, rather than hard-coding a specific age?
|
Good work on these tasks, I think this is complete now |
|
Your PR couldn't be matched to an assignment in this module. Please check its title is in the correct format, and that you only have one PR per assignment. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
1 similar comment
|
Your PR couldn't be matched to an assignment in this module. Please check its title is in the correct format, and that you only have one PR per assignment. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
Learners, PR Template
Self checklist
Changelist
I have done all the exercises in the prep section. I created a Python file per exercise.
Questions
Ready to review!