-
Notifications
You must be signed in to change notification settings - Fork 77
Added Session 07 Homework #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3595627
Session 6 Homework.
salimhamed e8b24cc
Added vim_demo file.
salimhamed 0f87352
finished session 07 homework
salimhamed 327b5d1
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroToP…
salimhamed 709d96f
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroToP…
salimhamed eac2067
Added sparse_array object with unit tests.
salimhamed 102b994
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroToP…
salimhamed 51c97fd
Generate lab, modified sparse array, decoratory lab.
salimhamed e47dbdf
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroToP…
salimhamed f70019d
finished generator lab.
salimhamed b36a2e2
Finished Session 09 Homework.
salimhamed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
|
|
||
| Dear Salim Sr, | ||
|
|
||
| Thank you very much for your generous donation of $101.00. We | ||
| appreciate your thoughtfullness and we will make sure your donation | ||
| goes to the right cause. | ||
|
|
||
| Kind Regards, | ||
| Donation Team | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
|
|
||
| Dear Zeina, | ||
|
|
||
| Thank you very much for your generous donation of $500.00. We | ||
| appreciate your thoughtfullness and we will make sure your donation | ||
| goes to the right cause. | ||
|
|
||
| Kind Regards, | ||
| Donation Team |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
|
|
||
| Dear Joanna Hamed, | ||
|
|
||
| Thank you very much for your generous donation of $100.00. We | ||
| appreciate your thoughtfullness and we will make sure your donation | ||
| goes to the right cause. | ||
|
|
||
| Kind Regards, | ||
| Donation Team |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/usr/local/bin/python | ||
|
|
||
| class Element(object): | ||
|
|
||
| def __init__(self, content=None): | ||
| self.content = content | ||
| def append(self, new_content): | ||
| self.content += new_content | ||
| def render(self, file_out, ind=""): | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| def incremental(n): | ||
| l = [] | ||
| for i in range(n): | ||
| l.append(lambda x, e=i: x + e) | ||
| return l |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!usr/local/bin/python | ||
|
|
||
| from math import pi | ||
|
|
||
|
|
||
| class Circle(object): | ||
| """Generic Circle class.""" | ||
|
|
||
| def __init__(self, radius): | ||
| self.radius = radius | ||
|
|
||
| @property | ||
| def diameter(self): | ||
| return self.radius * 2.0 | ||
|
|
||
| @diameter.setter | ||
| def diameter(self, value): | ||
| self.radius = value / 2.0 | ||
|
|
||
| @property | ||
| def area(self): | ||
| return pi * self.radius ** 2 | ||
|
|
||
| @classmethod | ||
| def from_diameter(cls, diameter): | ||
| return cls(diameter / 2.0) | ||
|
|
||
| def __str__(self): | ||
| return 'Circle with radius: {:.2f}'.format(self.radius) | ||
|
|
||
| def __repr__(self): | ||
| return 'Circle({})'.format(self.radius) | ||
|
|
||
| def __add__(self, other): | ||
| return Circle(self.radius + other.radius) | ||
|
|
||
| def __mul__(self, other): | ||
| return Circle(self.radius * other) | ||
|
|
||
| def __rmul__(self, other): | ||
| return Circle(self.radius * other) | ||
|
|
||
| def __cmp__(self, other): | ||
| result = float(self.radius) - float(other.radius) | ||
| return -1 if result < 0 else 1 if result > 0 else 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| #!usr/local/bin/python | ||
| from circle import Circle | ||
| from math import pi | ||
|
|
||
|
|
||
| def test_circle_class(): | ||
| c = Circle(2) | ||
| assert isinstance(c, Circle) | ||
|
|
||
|
|
||
| def test_radius(): | ||
| c = Circle(2.0) | ||
| assert c.radius == 2.0 | ||
|
|
||
|
|
||
| def test_get_diameter(): | ||
| c = Circle(2.5) | ||
| assert c.diameter == 5.0 | ||
|
|
||
|
|
||
| def test_set_diameter(): | ||
| c = Circle(4.3) | ||
| c.diameter = 3.0 | ||
| assert c.radius == 1.5 | ||
| assert c.diameter == 3.0 | ||
|
|
||
|
|
||
| def test_area(): | ||
| c = Circle(10) | ||
| assert c.area == pi * 10 ** 2 | ||
|
|
||
|
|
||
| def test_set_area(): | ||
| c = Circle(4) | ||
| try: | ||
| c.area = 10 | ||
| except AttributeError as error: | ||
| assert error.message == "can't set attribute" | ||
| else: | ||
| assert False | ||
|
|
||
|
|
||
| def test_from_diameter(): | ||
| c = Circle.from_diameter(10) | ||
| assert isinstance(c, Circle) | ||
| assert c.radius == 5.0 | ||
|
|
||
|
|
||
| def test_print_circle(): | ||
| c_int = Circle(3) | ||
| c_float = Circle(3.50) | ||
| assert str(c_int) == 'Circle with radius: 3.00' | ||
| assert str(c_float) == 'Circle with radius: 3.50' | ||
|
|
||
|
|
||
| def test_repr(): | ||
| c = Circle(3) | ||
| assert repr(c) == 'Circle(3)' | ||
|
|
||
|
|
||
| def test_add(): | ||
| a = Circle(10) | ||
| b = Circle(15) | ||
| assert isinstance(a + b, Circle) | ||
| assert (a + b).radius == Circle(25).radius | ||
|
|
||
|
|
||
| def test_multiply(): | ||
| a = Circle(10) | ||
| c_mult = a * 3 | ||
| assert isinstance(c_mult, Circle) | ||
| assert c_mult.radius == 30 | ||
|
|
||
| c2_mult = 4 * a | ||
| assert isinstance(c2_mult, Circle) | ||
| assert c2_mult.radius == 40 | ||
|
|
||
|
|
||
| def test_compare_circle(): | ||
| a3 = Circle(3) | ||
| b3 = Circle(3) | ||
| c5 = Circle(5) | ||
| d10 = Circle(10) | ||
| e3f = Circle(3.0) | ||
| assert not a3 > b3 | ||
| assert c5 > b3 | ||
| assert not c5 < b3 | ||
| assert a3 < d10 | ||
| assert a3 == b3 | ||
| assert not d10 == c5 | ||
|
|
||
|
|
||
| def test_sort(): | ||
| c_list = [Circle(6), Circle(7), Circle(15), Circle(1), Circle(6.5)] | ||
| c_list.sort() | ||
|
|
||
| sorted_list = [Circle(1), Circle(6), Circle(6.5), Circle(7), Circle(15)] | ||
| assert c_list[0].radius == sorted_list[0].radius | ||
| assert c_list[1].radius == sorted_list[1].radius | ||
| assert c_list[2].radius == sorted_list[2].radius | ||
| assert c_list[3].radius == sorted_list[3].radius | ||
| assert c_list[4].radius == sorted_list[4].radius |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| class Animal(object): | ||
| """Generic animal class""" | ||
|
|
||
| def __init__(self, name): | ||
| self.name = name | ||
|
|
||
| def walk(self): | ||
| print ('{} is Walking'.format(self.name)) | ||
|
|
||
| class Dog(Animal): | ||
| """Man's best friend""" | ||
|
|
||
| def bark(self): | ||
| print('Woof!') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!usr/local/bin/python | ||
|
|
||
|
|
||
| def intsum(): | ||
| args = [0, 1, 2, 3, 4, 5, 6, 7] | ||
| x = 0 | ||
| for i in args: | ||
| yield x + i | ||
| x = x + i | ||
|
|
||
|
|
||
| def doubler(): | ||
| args = range(1, 100) | ||
| x = 0 | ||
| for i in args: | ||
| yield max([x * 2, 1]) | ||
| x = max([x * 2, 1]) | ||
|
|
||
|
|
||
| def fib(): | ||
| l = [0, 0] | ||
| while True: | ||
| if sum(l) == 0: | ||
| yield 1 | ||
| l.append(1) | ||
| else: | ||
| yield sum(l) | ||
| l.append(sum(l)) | ||
| del l[0] | ||
|
|
||
|
|
||
| def prime(): | ||
| num = 1 | ||
| while True: | ||
| num += 1 | ||
| prime = True | ||
| for i in xrange(2, num + 1): | ||
| if num % i == 0 and i != num: | ||
| prime = False | ||
| break | ||
| if prime: | ||
| yield num |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: you generally don't want to add generated files to git....