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
| #!/usr/bin/env python3 | |
| WORD = 'EVAPORATE' | |
| if __name__ == '__main__': | |
| guessed = False | |
| build_word = list('_' * len(WORD)) | |
| print('>>> Welcome to Hangman!') | |
| print('_ ' * len(WORD)) |
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
| #!/usr/bin/env python3 | |
| from random import choice | |
| def pick_random_word(wordlist: list) -> str: | |
| """Pick a random number from a list of words.""" | |
| return choice(wordlist) | |
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
| #!/usr/bin/env python3 | |
| from sys import exit | |
| BOARD_SIZE = 3 | |
| BOARD = [['0', '0', '0'], | |
| ['0', '0', '0'], | |
| ['0', '0', '0']] | |
| SCORE = {'player_one': 0, 'player_two': 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
| #!/usr/bin/env python3 | |
| def max_of_three(first: int, second: int, third: int) -> int: | |
| """This function returns the maximum number out of three numbers.""" | |
| if first > second: | |
| if first > third: | |
| return first | |
| return third |
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
| #!/usr/bin/env python3 | |
| def check_win(board: list) -> int: | |
| """This function takes a board in form of a matrix aka a list of a list and | |
| checks whether any player has won the game.""" | |
| # Check if someone has won - line | |
| for row in board: | |
| if (row[0] == row[1] == row[2]) and (row[0] != 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
| #!/usr/bin/env python3 | |
| def binary_search() -> None: | |
| left = 0 | |
| right = 100 | |
| guesses = 0 | |
| while left <= right: | |
| guesses += 1 |
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
| #!/usr/bin/env python3 | |
| def create_line(columns: int) -> None: | |
| """This function draws a line full of character "squares".""" | |
| print(' ---' * columns, sep='') | |
| print('| ' * columns, '|', sep='') | |
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
| #!/usr/bin/env python3 | |
| def create_list_from_file(filename: str) -> list: | |
| """This function creates a list of all the numbers from the file given as | |
| argument to the function. It then returns the list. | |
| """ | |
| numbers = [] | |
| with open(filename) as 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
| #!/usr/bin/env python3 | |
| if __name__ == '__main__': | |
| filename = 'Training_01.txt' | |
| with open(filename) as sun_pictures: | |
| categories = {} | |
| line = sun_pictures.readline() | |
| while line: |
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
| #!/usr/bin/env python3 | |
| import requests | |
| from bs4 import BeautifulSoup | |
| if __name__ == '__main__': | |
| responseObj = requests.get('https://www.nytimes.com/') | |
| soup = BeautifulSoup(responseObj.text, 'html.parser') | |
| filename = input('Write the name of the file in which to write the ' |