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
| def gcden(x, y): | |
| while x % y != 0: | |
| oldx = x | |
| oldy = y | |
| x = oldy | |
| y = oldx % oldy | |
| return y |
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
| class Point: | |
| def __init__(self, initX, initY): | |
| self.x = initX | |
| self.y = initY | |
| def distanceFromOrigin(self): | |
| return ((self.x ** 2) + (self.y ** 2)) ** 0.5 | |
| def __str__(self): |
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
| class Point: | |
| def __init__(self, initX, initY): | |
| self.x = initX | |
| self.y = initY | |
| def distanceFromOrigin(self): | |
| return ((self.x ** 2) + (self.y ** 2)) ** 0.5 | |
| def __str__(self): |
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
| class Point: | |
| def __init__(self, initX, initY): | |
| self.x = initX | |
| self.y = initY | |
| def distanceFromOrigin(self): | |
| return ((self.x ** 2) + (self.y ** 2)) ** 0.5 | |
| def __str__(self): |
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
| class IrishPostalAddress(BasePostalAddress): | |
| def __init__(self, recipient, postalCode): | |
| super().__init__("IRELAND", recipient) | |
| self.postalCode = postalCode | |
| def display(self): | |
| print(self.recipient) | |
| print(self.postalCode) | |
| print(self.country) |
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
| class Player: | |
| def __init__(self, mark): | |
| # mark can be 'x' or 'o' | |
| self.mark = mark | |
| # different types of players can inherit from here, so >> pass | |
| def get_play(self, game): | |
| pass | |
| class HumanPlayer(Player): |
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
| from player_ttt import hPlayer | |
| class Tictactoe: | |
| # The tictactoe game board spot IDs will be: | |
| # 0 1 2 | |
| # 3 4 5 | |
| # 6 7 8 | |
| def __init__(self): | |
| # list of all spots in the game, mapping 0 thru 8 to spots on the 3x3 board | |
| self.spot_ids = [i for i in range(9)] | |
| # record of board spot values reflecting which player occupies a spot, and with a space representing an empty/available spot |
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
| from hrplayers_ttt import hPlayer, rPlayer | |
| class Tictactoe: | |
| # The tictactoe game board spot IDs will be: | |
| # 0 1 2 | |
| # 3 4 5 | |
| # 6 7 8 | |
| def __init__(self): | |
| # list of all spots in the game, mapping 0 thru 8 to spots on the 3x3 board | |
| self.spot_ids = [i for i in range(9)] | |
| # record of board spot values reflecting which player occupies a spot, and with a space representing an empty/available spot |
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
| import random | |
| def is_win(g, s): | |
| '''check for a win, assign win value, return boolean''' | |
| if all(g[i] == s[i] for i in range(len(s))): | |
| win = True | |
| print(f'You won! The code was {s}') | |
| return win | |
| else: | |
| win = False |
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
| a = (0, 1, 0) | |
| b = (1, -1, 1) | |
| c = [a, b, b] | |
| d = [b, a, a] | |
| e = [c, d] | |
| # user selects tuple index for comparison | |
| index_okay = False | |
| while not index_okay: | |
| try: |