Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 218 additions & 0 deletions Tasks.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
{
"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": 6,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Define the 4 matrices as A,B,C,\n",
"A= np.random.randint(1,10,size=(3,3))\n",
"B= np.random.randint(1,10,size=(3,3))\n",
"C= np.random.randint(1,10,size=(3,3))\n",
"D= np.random.randint(1,10,size=(3,3))\n"
],
"metadata": {
"id": "r1pVl7LbA1_I"
},
"execution_count": 21,
"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": "fecfee1a-9d55-40dc-d29f-903e3a45dac1"
},
"execution_count": 22,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[[6 6 8]\n",
" [7 3 6]\n",
" [9 5 1]]\n",
"[[3 3 4]\n",
" [6 1 4]\n",
" [9 4 7]]\n",
"[[2 3 6]\n",
" [1 9 2]\n",
" [5 2 1]]\n",
"[[6 7 9]\n",
" [9 2 4]\n",
" [2 4 2]]\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Find the Dot Product of matrices\n",
"np.dot(A,B,C,D)"
],
"metadata": {
"id": "MDcD7tOWBMzG",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 158
},
"outputId": "b4eca299-379a-41e9-dd9b-77d547558b77"
},
"execution_count": 23,
"outputs": [
{
"output_type": "error",
"ename": "TypeError",
"evalue": "dot() takes from 2 to 3 positional arguments but 4 were given",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-23-8b3819afdefb>\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Find the Dot Product of matrices\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mA\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mB\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mC\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mD\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m: dot() takes from 2 to 3 positional arguments but 4 were given"
]
}
]
},
{
"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": []
}
]
}