-
Couldn't load subscription status.
- Fork 2
Sourcery refactored master branch #9
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,7 @@ def is_prime(num): | |
| if num == 1: | ||
| return False | ||
|
|
||
| for i in range(2, num): | ||
| if num % i == 0: | ||
| return False | ||
|
|
||
| return True | ||
| return all(num % i != 0 for i in range(2, num)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Amazing! |
||
|
|
||
|
|
||
| def fizzbuzzwhiz(num): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
|
|
||
| def first_unique_character(s): | ||
| before = '' | ||
| for i in range(0, len(s)): | ||
| for i in range(len(s)): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| char = s[i] | ||
| after = s[i+1:] | ||
| if char not in before + after: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,7 @@ def is_prime(num): | |
|
|
||
| end = int(math.sqrt(num)) if num > 10 else num | ||
|
|
||
| for i in range(2, end): | ||
| if num % i == 0: | ||
| return False | ||
|
|
||
| return True | ||
| return all(num % i != 0 for i in range(2, end)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class PrimeNumbersTest(unittest.TestCase): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
|
|
||
| @app.task | ||
| def show(symbol, time_count): | ||
| for m in range(time_count): | ||
| for _ in range(time_count): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| print(symbol * time_count) | ||
| sleep(1) | ||
| return symbol | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,7 @@ def median(numbers): | |
| length = len(numbers) | ||
| half = length // 2 - int(length % 2 == 0) | ||
| middle = sorted(numbers)[half:-half] | ||
| median = sum(middle) / len(middle) | ||
| return median | ||
| return sum(middle) / len(middle) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| print(median(five_numbers)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,10 +13,7 @@ | |
| def is_prime(num): | ||
| if num == 1: | ||
| return False | ||
| for i in range(2, num): | ||
| if num % i == 0: | ||
| return False | ||
| return True | ||
| return all(num % i != 0 for i in range(2, num)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def odd_or_even(num): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,9 @@ | |
| def is_prime(n): | ||
| if n == 1: | ||
| return False | ||
| if n == 2 or n == 3: | ||
| if n in [2, 3]: | ||
| return True | ||
| for i in range(2, isqrt(n) + 1): | ||
| if n % i == 0: | ||
| return False | ||
| return True | ||
| return all(n % i != 0 for i in range(2, isqrt(n) + 1)) | ||
|
Comment on lines
-23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def fizzbuzzwhiz(n): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,81 +66,81 @@ def won_point(self, playerName): | |
| def score(self): | ||
| result = "" | ||
| if (self.p1points == self.p2points and self.p1points < 4): | ||
| if (self.p1points==0): | ||
| if self.p1points == 0: | ||
| result = "Love" | ||
| if (self.p1points==1): | ||
| elif self.p1points == 1: | ||
| result = "Fifteen" | ||
| if (self.p1points==2): | ||
| elif self.p1points == 2: | ||
| result = "Thirty" | ||
| if (self.p1points==3): | ||
| elif self.p1points == 3: | ||
| result = "Forty" | ||
| result += "-All" | ||
| if (self.p1points==self.p2points and self.p1points>3): | ||
| result = "Deuce" | ||
|
|
||
| P1res = "" | ||
| P2res = "" | ||
| if (self.p1points > 0 and self.p2points==0): | ||
| if (self.p1points==1): | ||
| if self.p1points == 1: | ||
| P1res = "Fifteen" | ||
| if (self.p1points==2): | ||
| elif self.p1points == 2: | ||
| P1res = "Thirty" | ||
| if (self.p1points==3): | ||
| elif self.p1points == 3: | ||
| P1res = "Forty" | ||
|
|
||
| P2res = "Love" | ||
| result = P1res + "-" + P2res | ||
| if (self.p2points > 0 and self.p1points==0): | ||
| if (self.p2points==1): | ||
| if self.p2points == 1: | ||
| P2res = "Fifteen" | ||
| if (self.p2points==2): | ||
| elif self.p2points == 2: | ||
| P2res = "Thirty" | ||
| if (self.p2points==3): | ||
| elif self.p2points == 3: | ||
| P2res = "Forty" | ||
|
|
||
| P1res = "Love" | ||
| result = P1res + "-" + P2res | ||
|
|
||
|
|
||
| if (self.p1points>self.p2points and self.p1points < 4): | ||
| if (self.p1points==2): | ||
| if self.p1points == 2: | ||
| P1res="Thirty" | ||
| if (self.p1points==3): | ||
| elif self.p1points == 3: | ||
| P1res="Forty" | ||
| if (self.p2points==1): | ||
| if self.p2points == 1: | ||
| P2res="Fifteen" | ||
| if (self.p2points==2): | ||
| elif self.p2points == 2: | ||
| P2res="Thirty" | ||
| result = P1res + "-" + P2res | ||
| if (self.p2points>self.p1points and self.p2points < 4): | ||
| if (self.p2points==2): | ||
| if self.p2points == 2: | ||
| P2res="Thirty" | ||
| if (self.p2points==3): | ||
| elif self.p2points == 3: | ||
| P2res="Forty" | ||
| if (self.p1points==1): | ||
| if self.p1points == 1: | ||
| P1res="Fifteen" | ||
| if (self.p1points==2): | ||
| elif self.p1points == 2: | ||
| P1res="Thirty" | ||
| result = P1res + "-" + P2res | ||
|
|
||
| if (self.p1points > self.p2points and self.p2points >= 3): | ||
| result = "Advantage " + self.player1Name | ||
|
|
||
| if (self.p2points > self.p1points and self.p1points >= 3): | ||
| result = "Advantage " + self.player2Name | ||
|
|
||
|
Comment on lines
-69
to
+131
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if (self.p1points>=4 and self.p2points>=0 and (self.p1points-self.p2points)>=2): | ||
| result = "Win for " + self.player1Name | ||
| if (self.p2points>=4 and self.p1points>=0 and (self.p2points-self.p1points)>=2): | ||
| result = "Win for " + self.player2Name | ||
| return result | ||
|
|
||
| def SetP1Score(self, number): | ||
| for i in range(number): | ||
| for _ in range(number): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.P1Score() | ||
|
|
||
| def SetP2Score(self, number): | ||
| for i in range(number): | ||
| for _ in range(number): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.P2Score() | ||
|
|
||
| def P1Score(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,16 +46,16 @@ | |
| ]) | ||
| def test_get_score(p1_points, p2_points, score, p1_name='player1', p2_name='player2'): | ||
| game = TennisGame(p1_name, p2_name) | ||
| for i in range(p1_points): | ||
| for _ in range(p1_points): | ||
| game.won_point(p1_name) | ||
| for i in range(p2_points): | ||
| for _ in range(p2_points): | ||
|
Comment on lines
-49
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| game.won_point(p2_name) | ||
| assert score == game.score() | ||
|
|
||
|
|
||
| def test_player_names(): | ||
| game = TennisGame('One', 'Two') | ||
| for i in range(4): | ||
| for _ in range(4): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| game.won_point('One') | ||
| assert "Win for One" == game.score() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.