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
"""Functions for printing a TicTacToe gameboard to the console | |
The gameboard should be represented as a 2 dimensional list of 3 rows and 3 columns | |
""" | |
element_process = lambda i: ("X" if i == 1 else ("O" if i == 2 else " ")) | |
def printboard(board): | |
print "\n game = [%s]\n" % ",\n\t ".join(["[%s]" % ", ".join(map(element_process, board[i])) for i in xrange(3)]) |
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
"""Get all <article> tags on New York Times homepage""" | |
import requests | |
from bs4 import BeautifulSoup | |
def get_articles(address): | |
page = requests.get(address) | |
soup = BeautifulSoup(page.text, "html.parser") | |
return list(soup.find_all("article")) | |
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
"""Fetch an online article and print it to the screen""" | |
import requests | |
from bs4 import BeautifulSoup | |
def getportions(soup): | |
heading = soup.find("div", {"class":"dek"}) | |
if heading: | |
yield heading.text | |
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 whosmax(*args): | |
start = 0 | |
limit = len(args) | |
i = 1 | |
while i < limit: | |
if args[start] < args[i]: start = i | |
i += 1 | |
return args[start] |
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
"""Functions for printing a TicTacToe gameboard to the console | |
The gameboard should be represented as a 2 dimensional list of 3 rows and 3 columns | |
""" | |
element_process = lambda i: ("X" if i == 1 else ("O" if i == 2 else " ")) | |
def printboard(board): | |
print "\n game = [%s]\n" % ",\n\t ".join(["[%s]" % ", ".join(map(element_process, board[i])) for i in xrange(3)]) |
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
"""Determine the winner of any of a game of tic tac toe | |
The results of the play woll be provided to the program as a | |
2 dimensional array of 3 lists which will contain numbers | |
indicating the mark on that spot on the board. | |
1 will represent play by player 1 | |
2 represent play by player 2 | |
0 inicates a blank cell | |
""" |
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
"""Guess the number that a user has chosen | |
The program will try to get the number guessed by the user | |
between 0 and 100 in as few guesses as possible | |
For each guess, the user will tell the program if the guess is too high or too low or correct | |
The program will also return the number of attempts it made at | |
establishing the number""" |
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
"""Gameboard Generator""" | |
columns = int(raw_input("How many columns do you want on your gameboard? ")) | |
rows = int(raw_input("How many rows do you want on your gameboard? ")) | |
def gameboard(columns,rows): | |
column = [] | |
height = [] | |
for i in range(columns): | |
column.append(" |") | |
for i in range(columns): |
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
"""Draw a X x Y matrix as per the specifications entered as input""" | |
def draw(x, y): | |
"""Draws a matrix of x rows and y columns""" | |
##The length of the 'dott' sequence can be adjusted and the rest of the | |
#drawing will adjust itself after reloading""" | |
dott = " ----- " | |
pipe = "|" | |
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 two text files, print the numbers or words that appear in both files""" | |
import os | |
def get_overlap(_file1, _file2): | |
with open(_file1, 'r') as f1, open(_file2, 'r') as f2: | |
return set(f1.read().split()).intersection(set(f2.read().split())) | |
if __name__ == "__main__": |
NewerOlder