From 2a173bb7f5d60aba44fb49809f8f7d36bd458b30 Mon Sep 17 00:00:00 2001 From: TimEisenmenger <83813379+TimEisenmenger@users.noreply.github.com> Date: Thu, 3 Jun 2021 23:18:44 +0200 Subject: [PATCH 1/4] Add files via upload --- your-code/README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 your-code/README.md diff --git a/your-code/README.md b/your-code/README.md new file mode 100644 index 0000000..ace452e --- /dev/null +++ b/your-code/README.md @@ -0,0 +1,49 @@ +Ironhack Logo + +# Programming the Game TicTacTow +Tim Eisenmenger + +DATA Analytics / FT / MAY2021 + +## Content +- [Project Description](#project-description) +- [Rules](#rules) +- [Workflow](#workflow) +- [Organization](#organization) +- [Links](#links) + +## Project Description +I have decided to program tictactoe because i have always enjoyed playing the game. It's simple and entertaining. Especially in school and university the game was always a good alternative to refresh boring classes + +## Rules +1. The game is played on a board that's 3 squares by 3 squares with numbers on them. The numbers are assigned as follows: + 1 - 2 - 3 + 4 - 5 - 6 + 7 - 8 - 9 +2. Player 1 has X, Player 2 has O. Players take turns putting their marks in empty squares. +3. The first player to get 3 of his/her marks in a row (up, down, across, or diagonally) is the winner. +4. When all 9 squares are full, the game is over. + +## Workflow +1. Research about the game. +2. Designing game structure. +3. Thinking about possible difficulties. +4. Cloning Repo in GitHub +5. MAINPART: Coding the Game! +6. Testing +7. Updating Repo with READ ME.file and gitignore.file + +## Organization +For organizing the different steps described in workflow i jused Trello. + +My repositiory contains the following: +1. READ ME.file --> Shows you how to play the game. +2. gitignore.file --> Shows files to ignore from Git +3. Last and final version of my code + +## Links +Include links to your repository, slides and kanban board. Feel free to include any other links associated with your project. + +[Repository](https://github.com/) +[Slides](https://slides.com/) +[Trello](https://trello.com/b/pKODM4B6/project-1-bulding-tic-tac-toe-with-python) From 7a4ec941decceed1975f6e7ecc27444431eea5ad Mon Sep 17 00:00:00 2001 From: TimEisenmenger <83813379+TimEisenmenger@users.noreply.github.com> Date: Thu, 3 Jun 2021 23:24:34 +0200 Subject: [PATCH 2/4] Delete README.md --- your-code/README.md | 49 --------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 your-code/README.md diff --git a/your-code/README.md b/your-code/README.md deleted file mode 100644 index ace452e..0000000 --- a/your-code/README.md +++ /dev/null @@ -1,49 +0,0 @@ -Ironhack Logo - -# Programming the Game TicTacTow -Tim Eisenmenger - -DATA Analytics / FT / MAY2021 - -## Content -- [Project Description](#project-description) -- [Rules](#rules) -- [Workflow](#workflow) -- [Organization](#organization) -- [Links](#links) - -## Project Description -I have decided to program tictactoe because i have always enjoyed playing the game. It's simple and entertaining. Especially in school and university the game was always a good alternative to refresh boring classes - -## Rules -1. The game is played on a board that's 3 squares by 3 squares with numbers on them. The numbers are assigned as follows: - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 -2. Player 1 has X, Player 2 has O. Players take turns putting their marks in empty squares. -3. The first player to get 3 of his/her marks in a row (up, down, across, or diagonally) is the winner. -4. When all 9 squares are full, the game is over. - -## Workflow -1. Research about the game. -2. Designing game structure. -3. Thinking about possible difficulties. -4. Cloning Repo in GitHub -5. MAINPART: Coding the Game! -6. Testing -7. Updating Repo with READ ME.file and gitignore.file - -## Organization -For organizing the different steps described in workflow i jused Trello. - -My repositiory contains the following: -1. READ ME.file --> Shows you how to play the game. -2. gitignore.file --> Shows files to ignore from Git -3. Last and final version of my code - -## Links -Include links to your repository, slides and kanban board. Feel free to include any other links associated with your project. - -[Repository](https://github.com/) -[Slides](https://slides.com/) -[Trello](https://trello.com/b/pKODM4B6/project-1-bulding-tic-tac-toe-with-python) From 2fc9522d0100d949fd0ce19421d3413e3a2c0eac Mon Sep 17 00:00:00 2001 From: Tim Eisenmenger Date: Tue, 8 Jun 2021 14:19:46 +0200 Subject: [PATCH 3/4] Update Lab3 --- your-code/My_First_Project.ipynb | 248 +++++++++++++++++++++++ your-code/main.ipynb | 335 ++++++++++++++++++++++++++++++- 2 files changed, 582 insertions(+), 1 deletion(-) create mode 100644 your-code/My_First_Project.ipynb diff --git a/your-code/My_First_Project.ipynb b/your-code/My_First_Project.ipynb new file mode 100644 index 0000000..c4f213d --- /dev/null +++ b/your-code/My_First_Project.ipynb @@ -0,0 +1,248 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Project 1: Building TicTacToe in Python" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Structure:" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "# 1. First of all we need to create the Playground of Tic Tac Toe.\n", + "\n", + "# 2. To play Tic Tac Toe we need to players and their names. \n", + "# --> Input: Player 1 & Input: Player 2\n", + "# 3. We need a function to decide who starts the game. In addition we need to signal the person who didn' start that its his/her turn.\n", + "\n", + "# 4. Function for placing the Symbols on the Playground\n", + "# --> Check if the space which is targeted is empty:\n", + " # - if yes, place it there\n", + " # - if no, advice to go for another field on the Playground\n", + " \n", + "# 5. When do we have a winner? \n", + " # - Declare winning condition\n", + " # - Player wins, if he has 3 of his Symbols in a row\n", + "\n", + "# 6. Make sure when its a Tie\n", + " \n", + "# 6. Ask the players if they want to play again" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Creating the Game Board:" + ] + }, + { + "cell_type": "code", + "execution_count": 173, + "metadata": {}, + "outputs": [], + "source": [ + "board = {\"1\": \" \", \"2\": \" \", \"3\": \" \" ,\n", + " \"4\": \" \", \"5\": \" \", \"6\": \" \" ,\n", + " \"7\": \" \", \"8\": \" \", \"9\": \" \" }" + ] + }, + { + "cell_type": "code", + "execution_count": 174, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "\n", + "\n", + "def game_board(board):\n", + " '''\n", + " Creates our game board\n", + " Input: Dictionary with 9 keys and empty values\n", + " Output: Prints updated game board\n", + " '''\n", + " \n", + " \n", + " print(board[\"1\"] + \"|\" + board[\"2\"] + \"|\" + board[\"3\"])\n", + " print(\"-----\")\n", + " print(board[\"4\"] + \"|\" + board[\"5\"] + \"|\" + board[\"6\"])\n", + " print(\"-----\")\n", + " print(board[\"7\"] + \"|\" + board[\"8\"] + \"|\" + board[\"9\"])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 175, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " | | \n", + "-----\n", + " | | \n", + "-----\n", + " | | \n" + ] + } + ], + "source": [ + "game_board(board)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Defining Players Names and randomly chose who starts" + ] + }, + { + "cell_type": "code", + "execution_count": 176, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Player_1, please enter your name here: Tim\n", + "Player_2, please enter your name here: Max\n" + ] + }, + { + "data": { + "text/plain": [ + "'Max starts the game! Your Symbol is X'" + ] + }, + "execution_count": 176, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# a = Name Player 1\n", + "# b = Name Player 2\n", + "\n", + "\n", + "def starting_player(a,b):\n", + " '''\n", + " Implements players names and randomly picks who starts the game\n", + " Input:\n", + " a = Input Name Player 1\n", + " b = Input Name Player 2\n", + " Output:\n", + " Returns random Player out of a,b\n", + " '''\n", + " a = input(\"Player_1, please enter your name here: \")\n", + " b = input(\"Player_2, please enter your name here: \")\n", + " \n", + " import random\n", + " \n", + " players = [a, b]\n", + " return(random.choice(players) + \" \" + \"starts the game!\" + \" \" + \"Your Symbol is X\")\n", + "\n", + "starting_player(a,b) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup Function to put Symbols on the game board" + ] + }, + { + "cell_type": "code", + "execution_count": 177, + "metadata": {}, + "outputs": [], + "source": [ + "def game():\n", + " '''\n", + " Function to place players symbols on the game board\n", + " Input:\n", + " Number between 1 und 10\n", + " Output:\n", + " Checks if the field is empty or not:\n", + " 1. if yes -> put the symbol there\n", + " 2. if no -> tell the player to chose again\n", + " \n", + " '''\n", + " cross = \"X\"\n", + " circle = \"O\"\n", + " \n", + " for i in range(10):\n", + " print(game_board(board))\n", + " print(\" \")\n", + " print(\"It's your turn, \" + cross + \".\" + \" \" + \"Where do you want to move?\")\n", + " \n", + " z = str(input())\n", + " \n", + " if board[z] == \" \":\n", + " board[z] = cross\n", + " else: \n", + " print(\"SHIT!\" + \"This position is already filled.\" + \" Please chose another one!\")\n", + " continue\n", + " \n", + " \n", + " if cross == \"X\":\n", + " cross = \"O\"\n", + " else:\n", + " cross = \"X\"\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Set up winning condition" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/your-code/main.ipynb b/your-code/main.ipynb index b44af58..9e773fb 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -1 +1,334 @@ -{"cells":[{"cell_type":"markdown","metadata":{},"source":["# Before your start:\n","- Read the README.md file\n","- Comment as much as you can and use the resources in the README.md file\n","- Happy learning!"]},{"cell_type":"code","execution_count":1,"metadata":{},"outputs":[],"source":"import re"},{"cell_type":"markdown","metadata":{},"source":"# Challenge 1 - Combining Strings\n\nCombining strings is an important skill to acquire. There are multiple ways of combining strings in Python, as well as combining strings with variables. We will explore this in the first challenge. In the cell below, combine the strings in the list and add spaces between the strings (do not add a space after the last string). Insert a period after the last string."},{"cell_type":"code","execution_count":2,"metadata":{},"outputs":[{"data":{"text/plain":"'Durante un tiempo no estuvo segura de si su marido era su marido'"},"execution_count":2,"metadata":{},"output_type":"execute_result"}],"source":"str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n# Your code here:\n"},{"cell_type":"markdown","metadata":{},"source":"In the cell below, use the list of strings to create a grocery list. Start the list with the string `Grocery list: ` and include a comma and a space between each item except for the last one. Include a period at the end. Only include foods in the list that start with the letter 'b' and ensure all foods are lower case."},{"cell_type":"code","execution_count":3,"metadata":{},"outputs":[{"data":{"text/plain":"'bananas, bread, brownie mix, broccoli.'"},"execution_count":3,"metadata":{},"output_type":"execute_result"}],"source":"food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n# Your code here:\n"},{"cell_type":"markdown","metadata":{},"source":"In the cell below, compute the area of a circle using its radius and insert the radius and the area between `string1` and `string2`. Make sure to include spaces between the variable and the strings. \n\nNote: You can use the techniques we have learned so far or use f-strings. F-strings allow us to embed code inside strings. You can read more about f-strings [here](https://www.python.org/dev/peps/pep-0498/)."},{"cell_type":"code","execution_count":4,"metadata":{},"outputs":[],"source":"import math\n\nstring1 = \"The area of the circle with radius:\"\nstring2 = \"is:\"\nradius = 4.5\npi = math.pi\n\n# Your code here:\n"},{"cell_type":"markdown","metadata":{},"source":"# Challenge 2 - Splitting Strings\n\nWe have first looked at combining strings into one long string. There are times where we need to do the opposite and split the string into smaller components for further analysis. \n\nIn the cell below, split the string into a list of strings using the space delimiter. Count the frequency of each word in the string in a dictionary. Strip the periods, line breaks and commas from the text. Make sure to remove empty strings from your dictionary."},{"cell_type":"code","execution_count":5,"metadata":{},"outputs":[],"source":"poem = \"\"\"Some say the world will end in fire,\nSome say in ice.\nFrom what I’ve tasted of desire\nI hold with those who favor fire.\nBut if it had to perish twice,\nI think I know enough of hate\nTo say that for destruction ice\nIs also great\nAnd would suffice.\"\"\"\n\n# Your code here:\n"},{"cell_type":"markdown","metadata":{},"source":"In the cell below, find all the words that appear in the text and do not appear in the blacklist. You must parse the string but can choose any data structure you wish for the words that do not appear in the blacklist. Remove all non letter characters and convert all words to lower case."},{"cell_type":"code","execution_count":6,"metadata":{},"outputs":[],"source":"blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n\npoem = \"\"\"I was angry with my friend; \nI told my wrath, my wrath did end.\nI was angry with my foe: \nI told it not, my wrath did grow. \n\nAnd I waterd it in fears,\nNight & morning with my tears: \nAnd I sunned it with smiles,\nAnd with soft deceitful wiles. \n\nAnd it grew both day and night. \nTill it bore an apple bright. \nAnd my foe beheld it shine,\nAnd he knew that it was mine. \n\nAnd into my garden stole, \nWhen the night had veild the pole; \nIn the morning glad I see; \nMy foe outstretched beneath the tree.\"\"\"\n\n# Your code here:\n\n"},{"cell_type":"markdown","metadata":{},"source":"# Bonus 1 - Regular Expressions\n\nSometimes, we would like to perform more complex manipulations of our string. This is where regular expressions come in handy. In the cell below, return all characters that are upper case from the string specified below."},{"cell_type":"code","execution_count":7,"metadata":{},"outputs":[],"source":"poem = \"\"\"The apparition of these faces in the crowd;\nPetals on a wet, black bough.\"\"\"\n\n# Your code here:\n"},{"cell_type":"markdown","metadata":{},"source":"In the cell below, filter the list provided and return all elements of the list containing a number. To filter the list, use the `re.search` function. Check if the function does not return `None`. You can read more about the `re.search` function [here](https://docs.python.org/3/library/re.html)."},{"cell_type":"code","execution_count":8,"metadata":{},"outputs":[],"source":"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n\n# Your code here:\n"},{"cell_type":"markdown","metadata":{},"source":"# Bonus 2 - Regular Expressions II\n\nIn the cell below, filter the list provided to keep only strings containing at least one digit and at least one lower case letter. As in the previous question, use the `re.search` function and check that the result is not `None`.\n\nTo read more about regular expressions, check out [this link](https://developers.google.com/edu/python/regular-expressions)."},{"cell_type":"code","execution_count":9,"metadata":{},"outputs":[],"source":"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n\n# Your code here:\n"}],"nbformat":4,"nbformat_minor":2,"metadata":{"language_info":{"name":"python","codemirror_mode":{"name":"ipython","version":3}},"orig_nbformat":2,"file_extension":".py","mimetype":"text/x-python","name":"python","npconvert_exporter":"python","pygments_lexer":"ipython3","version":3}} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Before your start:\n", + "- Read the README.md file\n", + "- Comment as much as you can and use the resources in the README.md file\n", + "- Happy learning!" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import re" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Challenge 1 - Combining Strings\n", + "\n", + "Combining strings is an important skill to acquire. There are multiple ways of combining strings in Python, as well as combining strings with variables. We will explore this in the first challenge. In the cell below, combine the strings in the list and add spaces between the strings (do not add a space after the last string). Insert a period after the last string." + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Durante un tiempo no estuvo segura de si su marido era su marido.\n" + ] + } + ], + "source": [ + "str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", + "\n", + "s = \" \".join(str_list) + \".\"\n", + "\n", + "print(s)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the cell below, use the list of strings to create a grocery list. Start the list with the string `Grocery list: ` and include a comma and a space between each item except for the last one. Include a period at the end. Only include foods in the list that start with the letter 'b' and ensure all foods are lower case." + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Grocery list: bananas, bread, brownie mix, broccoli.\n" + ] + } + ], + "source": [ + "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", + "grocery_list = []\n", + "grocery_list.append(\"Grocery list:\")\n", + "\n", + "for i in food_list:\n", + " if i[0].lower() == \"b\":\n", + " grocery_list.append(i.lower())\n", + " else:\n", + " pass\n", + " \n", + "\n", + "z = \", \".join(grocery_list) + \".\"\n", + "z = z.replace(\",\",\"\",1)\n", + "print(z)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the cell below, compute the area of a circle using its radius and insert the radius and the area between `string1` and `string2`. Make sure to include spaces between the variable and the strings. \n", + "\n", + "Note: You can use the techniques we have learned so far or use f-strings. F-strings allow us to embed code inside strings. You can read more about f-strings [here](https://www.python.org/dev/peps/pep-0498/)." + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The area of the circle with radius: 4.5 is: 63.61725123519331\n" + ] + } + ], + "source": [ + "import math\n", + "\n", + "string1 = \"The area of the circle with radius:\"\n", + "string2 = \"is:\"\n", + "radius = 4.5\n", + "pi = math.pi\n", + "\n", + "# Your code here:\n", + "area = math.pi * radius**2\n", + "print(f\"{string1} {radius} {string2} {area}\")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Challenge 2 - Splitting Strings\n", + "\n", + "We have first looked at combining strings into one long string. There are times where we need to do the opposite and split the string into smaller components for further analysis. \n", + "\n", + "In the cell below, split the string into a list of strings using the space delimiter. Count the frequency of each word in the string in a dictionary. Strip the periods, line breaks and commas from the text. Make sure to remove empty strings from your dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire,', 'Some', 'say', 'in', 'ice.', 'From', 'what', 'I’ve', 'tasted', 'of', 'desire', 'I', 'hold', 'with', 'those', 'who', 'favor', 'fire.', 'But', 'if', 'it', 'had', 'to', 'perish', 'twice,', 'I', 'think', 'I', 'know', 'enough', 'of', 'hate', 'To', 'say', 'that', 'for', 'destruction', 'ice', 'Is', 'also', 'great', 'And', 'would', 'suffice.']\n" + ] + } + ], + "source": [ + "poem = \"\"\"Some say the world will end in fire,\n", + "Some say in ice.\n", + "From what I’ve tasted of desire\n", + "I hold with those who favor fire.\n", + "But if it had to perish twice,\n", + "I think I know enough of hate\n", + "To say that for destruction ice\n", + "Is also great\n", + "And would suffice.\"\"\"\n", + "\n", + "# Your code here:\n", + "poem_new = poem.split()\n", + "print(poem_new)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Some': 2, 'say': 3, 'the': 1, 'world': 1, 'will': 1, 'end': 1, 'in': 2, 'fire,': 1, 'ice.': 1, 'From': 1, 'what': 1, 'I’ve': 1, 'tasted': 1, 'of': 2, 'desire': 1, 'I': 3, 'hold': 1, 'with': 1, 'those': 1, 'who': 1, 'favor': 1, 'fire.': 1, 'But': 1, 'if': 1, 'it': 1, 'had': 1, 'to': 1, 'perish': 1, 'twice,': 1, 'think': 1, 'know': 1, 'enough': 1, 'hate': 1, 'To': 1, 'that': 1, 'for': 1, 'destruction': 1, 'ice': 1, 'Is': 1, 'also': 1, 'great': 1, 'And': 1, 'would': 1, 'suffice.': 1}\n" + ] + } + ], + "source": [ + "frequencies = {}\n", + "for elem in poem_new:\n", + " if elem in frequencies:\n", + " frequencies[elem] += 1\n", + " else:\n", + " frequencies[elem] = 1\n", + "print(frequencies)" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire,', 'Some', 'say', 'in', 'ice.', 'From', 'what', 'I’ve', 'tasted', 'of', 'desire', 'I', 'hold', 'with', 'those', 'who', 'favor', 'fire.', 'But', 'if', 'it', 'had', 'to', 'perish', 'twice,', 'I', 'think', 'I', 'know', 'enough', 'of', 'hate', 'To', 'say', 'that', 'for', 'destruction', 'ice', 'Is', 'also', 'great', 'And', 'would', 'suffice.']\n" + ] + } + ], + "source": [ + "for item in poem_new:\n", + " item.strip(\",\")\n", + "print(poem_new)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the cell below, find all the words that appear in the text and do not appear in the blacklist. You must parse the string but can choose any data structure you wish for the words that do not appear in the blacklist. Remove all non letter characters and convert all words to lower case." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n", + "\n", + "poem = \"\"\"I was angry with my friend; \n", + "I told my wrath, my wrath did end.\n", + "I was angry with my foe: \n", + "I told it not, my wrath did grow. \n", + "\n", + "And I waterd it in fears,\n", + "Night & morning with my tears: \n", + "And I sunned it with smiles,\n", + "And with soft deceitful wiles. \n", + "\n", + "And it grew both day and night. \n", + "Till it bore an apple bright. \n", + "And my foe beheld it shine,\n", + "And he knew that it was mine. \n", + "\n", + "And into my garden stole, \n", + "When the night had veild the pole; \n", + "In the morning glad I see; \n", + "My foe outstretched beneath the tree.\"\"\"\n", + "\n", + "# Your code here:\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Bonus 1 - Regular Expressions\n", + "\n", + "Sometimes, we would like to perform more complex manipulations of our string. This is where regular expressions come in handy. In the cell below, return all characters that are upper case from the string specified below." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "poem = \"\"\"The apparition of these faces in the crowd;\n", + "Petals on a wet, black bough.\"\"\"\n", + "\n", + "# Your code here:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the cell below, filter the list provided and return all elements of the list containing a number. To filter the list, use the `re.search` function. Check if the function does not return `None`. You can read more about the `re.search` function [here](https://docs.python.org/3/library/re.html)." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", + "\n", + "# Your code here:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Bonus 2 - Regular Expressions II\n", + "\n", + "In the cell below, filter the list provided to keep only strings containing at least one digit and at least one lower case letter. As in the previous question, use the `re.search` function and check that the result is not `None`.\n", + "\n", + "To read more about regular expressions, check out [this link](https://developers.google.com/edu/python/regular-expressions)." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", + "\n", + "# Your code here:\n" + ] + } + ], + "metadata": { + "file_extension": ".py", + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5" + }, + "mimetype": "text/x-python", + "name": "python", + "npconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": 3 + }, + "nbformat": 4, + "nbformat_minor": 2 +} From b906fbc08a1381c9e05cb41ef86d96ba35434095 Mon Sep 17 00:00:00 2001 From: Tim Eisenmenger Date: Tue, 8 Jun 2021 14:23:13 +0200 Subject: [PATCH 4/4] Update Lab3 --- your-code/My_First_Project.ipynb | 248 ------------------------------- 1 file changed, 248 deletions(-) delete mode 100644 your-code/My_First_Project.ipynb diff --git a/your-code/My_First_Project.ipynb b/your-code/My_First_Project.ipynb deleted file mode 100644 index c4f213d..0000000 --- a/your-code/My_First_Project.ipynb +++ /dev/null @@ -1,248 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Project 1: Building TicTacToe in Python" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Structure:" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [], - "source": [ - "# 1. First of all we need to create the Playground of Tic Tac Toe.\n", - "\n", - "# 2. To play Tic Tac Toe we need to players and their names. \n", - "# --> Input: Player 1 & Input: Player 2\n", - "# 3. We need a function to decide who starts the game. In addition we need to signal the person who didn' start that its his/her turn.\n", - "\n", - "# 4. Function for placing the Symbols on the Playground\n", - "# --> Check if the space which is targeted is empty:\n", - " # - if yes, place it there\n", - " # - if no, advice to go for another field on the Playground\n", - " \n", - "# 5. When do we have a winner? \n", - " # - Declare winning condition\n", - " # - Player wins, if he has 3 of his Symbols in a row\n", - "\n", - "# 6. Make sure when its a Tie\n", - " \n", - "# 6. Ask the players if they want to play again" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Creating the Game Board:" - ] - }, - { - "cell_type": "code", - "execution_count": 173, - "metadata": {}, - "outputs": [], - "source": [ - "board = {\"1\": \" \", \"2\": \" \", \"3\": \" \" ,\n", - " \"4\": \" \", \"5\": \" \", \"6\": \" \" ,\n", - " \"7\": \" \", \"8\": \" \", \"9\": \" \" }" - ] - }, - { - "cell_type": "code", - "execution_count": 174, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "\n", - "\n", - "def game_board(board):\n", - " '''\n", - " Creates our game board\n", - " Input: Dictionary with 9 keys and empty values\n", - " Output: Prints updated game board\n", - " '''\n", - " \n", - " \n", - " print(board[\"1\"] + \"|\" + board[\"2\"] + \"|\" + board[\"3\"])\n", - " print(\"-----\")\n", - " print(board[\"4\"] + \"|\" + board[\"5\"] + \"|\" + board[\"6\"])\n", - " print(\"-----\")\n", - " print(board[\"7\"] + \"|\" + board[\"8\"] + \"|\" + board[\"9\"])\n" - ] - }, - { - "cell_type": "code", - "execution_count": 175, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " | | \n", - "-----\n", - " | | \n", - "-----\n", - " | | \n" - ] - } - ], - "source": [ - "game_board(board)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Defining Players Names and randomly chose who starts" - ] - }, - { - "cell_type": "code", - "execution_count": 176, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Player_1, please enter your name here: Tim\n", - "Player_2, please enter your name here: Max\n" - ] - }, - { - "data": { - "text/plain": [ - "'Max starts the game! Your Symbol is X'" - ] - }, - "execution_count": 176, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# a = Name Player 1\n", - "# b = Name Player 2\n", - "\n", - "\n", - "def starting_player(a,b):\n", - " '''\n", - " Implements players names and randomly picks who starts the game\n", - " Input:\n", - " a = Input Name Player 1\n", - " b = Input Name Player 2\n", - " Output:\n", - " Returns random Player out of a,b\n", - " '''\n", - " a = input(\"Player_1, please enter your name here: \")\n", - " b = input(\"Player_2, please enter your name here: \")\n", - " \n", - " import random\n", - " \n", - " players = [a, b]\n", - " return(random.choice(players) + \" \" + \"starts the game!\" + \" \" + \"Your Symbol is X\")\n", - "\n", - "starting_player(a,b) \n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setup Function to put Symbols on the game board" - ] - }, - { - "cell_type": "code", - "execution_count": 177, - "metadata": {}, - "outputs": [], - "source": [ - "def game():\n", - " '''\n", - " Function to place players symbols on the game board\n", - " Input:\n", - " Number between 1 und 10\n", - " Output:\n", - " Checks if the field is empty or not:\n", - " 1. if yes -> put the symbol there\n", - " 2. if no -> tell the player to chose again\n", - " \n", - " '''\n", - " cross = \"X\"\n", - " circle = \"O\"\n", - " \n", - " for i in range(10):\n", - " print(game_board(board))\n", - " print(\" \")\n", - " print(\"It's your turn, \" + cross + \".\" + \" \" + \"Where do you want to move?\")\n", - " \n", - " z = str(input())\n", - " \n", - " if board[z] == \" \":\n", - " board[z] = cross\n", - " else: \n", - " print(\"SHIT!\" + \"This position is already filled.\" + \" Please chose another one!\")\n", - " continue\n", - " \n", - " \n", - " if cross == \"X\":\n", - " cross = \"O\"\n", - " else:\n", - " cross = \"X\"\n", - " " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Set up winning condition" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.5" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -}