diff --git a/Tasks.ipynb b/Tasks.ipynb new file mode 100644 index 0000000..344bf2b --- /dev/null +++ b/Tasks.ipynb @@ -0,0 +1,204 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# **Task 1**\n", + "\n", + "Your goal is to find the answer of the dot product of the matrices of sizes (2,3), (3,5), (5,2) and (3,3).\n", + "\n", + "## **Workflow:**\n", + "1. Define the matrices of given sizes.\n", + "2. Print the matrices.\n", + "3. Use the np.dot function.\n", + "4. Print the output at each step.\n", + "5. Print the result.\n", + "\n", + "(Print the shape of matrix always with the matrix)\n" + ], + "metadata": { + "id": "6LkPygla_OXh" + } + }, + { + "cell_type": "code", + "source": [ + "# Import Numpy\n", + "import numpy as np" + ], + "metadata": { + "id": "Z8iSVv-r_WkT" + }, + "execution_count": 3, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Define the 4 matrices as A,B,C,D\n", + "A= np.random.randint(1, 10, size=(2, 3))\n", + "B= np.random.randint(1, 10, size=(3, 5))\n", + "C= np.random.randint(1, 10, size=(5, 2))\n", + "D= np.random.randint(1, 10, size=(3, 3))" + ], + "metadata": { + "id": "r1pVl7LbA1_I" + }, + "execution_count": 11, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Print the 4 matrices\n", + "print(A)\n", + "print(B)\n", + "print(C)\n", + "print(D)" + ], + "metadata": { + "id": "uJHj_CbhA83b", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "f4b9108c-aa46-4629-94d9-ee474dafe095" + }, + "execution_count": 12, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[2 7 3]\n", + " [2 7 4]]\n", + "[[7 6 3 2 7]\n", + " [9 8 2 5 3]\n", + " [8 2 6 2 8]]\n", + "[[9 1]\n", + " [2 7]\n", + " [7 1]\n", + " [3 5]\n", + " [3 6]]\n", + "[[9 9 6]\n", + " [2 3 9]\n", + " [4 7 5]]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "# Find the Dot Product of matrices\n", + "m = np.dot(A,D)\n", + "n = np.dot(m,B)\n", + "o = np.dot(n,C)" + ], + "metadata": { + "id": "MDcD7tOWBMzG" + }, + "execution_count": 17, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# ValueError: shapes (2,2) and (3,3) not aligned: 2 (dim 1) != 3 (dim 0)\n", + "\n", + "Now the task is to define a function named is_compatible() that takes 2 matrices as input and only allows the dot product if the condition number of **columns** in the first matrix (A) matches the number of **rows** in the second matrix (B).\n", + "\n", + "Print the ouput if condition is satisfied\n", + "Else print \"Dimension Error!!\"\n", + "\n", + "\n" + ], + "metadata": { + "id": "Rv1D09dyB0eP" + } + }, + { + "cell_type": "code", + "source": [ + "def is_compatible(A, B):\n", + " pass" + ], + "metadata": { + "id": "RmS0xS8tCjNC" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Find Dot product only if the matrices are compatible" + ], + "metadata": { + "id": "ds0XYSZ6E9nl" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# **Task 2**\n", + "\n", + "Your goal is to define a function that simulates a number-guessing game called \"Up-Down.\" The function, named up_down, should take an integer rounds as input, representing the number of turns the player gets.\n", + "\n", + "Game Rules:\n", + "\n", + "1. The player inputs a number between 1 and 12 for each round.\n", + "2. The computer randomly selects a number between 1 and 12.\n", + "3. The scoring system is as follows:\n", + " \n", + " a. If computer's guess is less than 7 and the player gains points equivalent to their guess if their guess is also less than 7, otherwise, they lose points equivalent to their guess.\n", + " \n", + " b. If computer's guess is exactly 7, the player gains 14 points if thier guess is 7, otherwise, they lose points equivalent to their guess.\n", + " \n", + " c. If computer's guess is greater than 7 and the player gains points equivalent to their guess if their guess is also greater than 7, otherwise, they lose points equivalent to their guess.\n", + "\n", + "4. The game continues until:\n", + "\n", + " a. The player reaches more than 30 points, they win.\n", + "\n", + " b. The player reaches less than -30 points, they lose.\n", + "\n", + " c. The maximum number of rounds is reached.\n", + " \n", + "At the end of the game, the function should print the final score.\n", + "\n", + "Your task is to implement this function in Python using the given rules." + ], + "metadata": { + "id": "SR_JeHeEdWOX" + } + }, + { + "cell_type": "code", + "source": [ + "def up_down(rounds):\n", + " pass" + ], + "metadata": { + "id": "0fxnUDma7aPx" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file