Last active
May 30, 2021 00:12
-
-
Save ankitml/c0318c0a71dc496224fc1909800251a0 to your computer and use it in GitHub Desktop.
Presenter.ipynb
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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Presenter.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/ankitml/c0318c0a71dc496224fc1909800251a0/presenter.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "PNZipUq0bSZO" | |
}, | |
"source": [ | |
"#**Quiz Time**\n", | |
"\n", | |
"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Tq6fBkA2311d" | |
}, | |
"source": [ | |
"### You have successfuly completed the first pyhton course and have revised all the concepts. Now its time to check how much have you learn. This whole class is one big quiz. \n", | |
"\n", | |
"Starting with basics, the questions will keep getting tougher as we progress. The quiz will go through all the concepts you learnt in the since the start of the course, there are moslty straightforward questions but some of them migh get tricky.\n", | |
"\n", | |
"The questions marked with a '*' are coding questions.\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "aQGS_WiqGw5U" | |
}, | |
"source": [ | |
"Q: Result of the expression (also will it be an int, float, string or boolean?):\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "zOLa1RGg4s3L" | |
}, | |
"source": [ | |
" (4 * (5 // 3)) ** 2" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "7ja2ynxD4rVz" | |
}, | |
"source": [ | |
"\n", | |
"Q: Result of the expression (also will it be an int, float, string or boolean?):\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "TBEBPj_O4qdj" | |
}, | |
"source": [ | |
" 5 * 6 / 2 + (2 + 5 - 4)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "qXfASzwgmVQN" | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "NzQ0w1gbe_jc" | |
}, | |
"source": [ | |
"Q: Output of the following code\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "E639e_a05W7S" | |
}, | |
"source": [ | |
"print(1+0)\n", | |
"print('==========')\n", | |
"\n", | |
"print('1' + '0')\n", | |
"print('==========')\n", | |
"\n", | |
"print(1,0)\n", | |
"print('==========')\n", | |
"\n", | |
"print(1,'\\n',0)\n", | |
"print('==========')\n", | |
"\n", | |
"print('10\\n')\n", | |
"print('==========')\n", | |
"\n", | |
"print('1\\n0')\n", | |
"print('==========')\n", | |
"\n", | |
"print('10\\n'*3)\n", | |
"print('==========')\n", | |
"\n", | |
"print('1\\n0'*3)\n", | |
"print('==========')\n" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "mSECFzbtbQAZ" | |
}, | |
"source": [ | |
"Q: Which of the is **not** a keyword in python\n", | |
"\n", | |
"- list\n", | |
"- dict\n", | |
"- in\n", | |
"- string\n", | |
"- for\n", | |
"- not\n", | |
"- and\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "DTollZGA5lxN" | |
}, | |
"source": [ | |
"Q: Output of the following code\n", | |
"\n", | |
" print( [1,2,3] + [3,2,1] )\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "O6_xwGws6ZjT" | |
}, | |
"source": [ | |
"Q: Output of this code:\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "yEoHK66_8SxD" | |
}, | |
"source": [ | |
"s = 'hello python'\n", | |
"s[3] = 't'\n", | |
"print(s)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "xiFubSxk6aD0" | |
}, | |
"source": [ | |
"Q: How do you make the above code work? (Hint: use list)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "XW8ILw0hk1Pi" | |
}, | |
"source": [ | |
"s = 'hello python'\n", | |
"s=list(s)\n", | |
"s[3]='t'\n", | |
"print(s)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "T61U_e-3uCk_" | |
}, | |
"source": [ | |
"Q: What is the output of the following code?\n", | |
"\n", | |
" s = \"pynative\"\n", | |
" print (s[1:3])\n", | |
"\n", | |
"- py\n", | |
"- yn\n", | |
"- pyn\n", | |
"- yna\n", | |
"\n", | |
"\n", | |
"\n", | |
"Q: What is the output of the following code?\n", | |
"\n", | |
" var= \"James Bond\"\n", | |
" print(var[2::-1])\n", | |
"- Jam\n", | |
"- dno\n", | |
"- maJ\n", | |
"- dnoB semaJ\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "g2KG6AePeO9v" | |
}, | |
"source": [ | |
"Q: What is the use of an 'if statement'?\n", | |
"\n", | |
"- to make the code run faster\n", | |
"- to make different pathways in the code\n", | |
"- to make the code easier to read\n", | |
"\n", | |
"\n", | |
" \n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "bCVzjlmPfqCY" | |
}, | |
"source": [ | |
"Q: Output of the following code:\n", | |
"\n", | |
" n = 5\n", | |
" if(n >= 3):\n", | |
" print('yes')\n", | |
" else:\n", | |
" print('no')\n", | |
" elif(n == 3):\n", | |
" print('equal')\n", | |
"\n", | |
"\n", | |
"\n", | |
" \n", | |
"Q: Output of the following code:\n", | |
"\n", | |
" n = 100\n", | |
" if(n > 50):\n", | |
" print('cake')\n", | |
" elif(n < 200):\n", | |
" print('pizza')\n", | |
" else:\n", | |
" print('burger')\n", | |
"\n", | |
"\n", | |
"\n", | |
"Q: Output of the following code:\n", | |
"\n", | |
" n = 100\n", | |
" if(n > 50):\n", | |
" print('cake')\n", | |
" if(n < 200):\n", | |
" print('pizza')\n", | |
" else:\n", | |
" print('burger')\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "7iW0QhFnlphD" | |
}, | |
"source": [ | |
"Q: Tell if the following lists are valid or not:\n", | |
"\n", | |
"- [5, 6, 7]\n", | |
"- ['5', '6', '7']\n", | |
"- [5, '6', 7]\n", | |
"- [2+3, 3+3, 4+3]\n", | |
"- [2+3, '3+3', 4+3]\n", | |
"- [ [ 5 ], [ 6 ], [ 7 ] ]\n", | |
"- ['5, 6, 7']\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "1GaGE-2Thnof" | |
}, | |
"source": [ | |
"Q: How many times will 'cake' be printed?\n", | |
"\n", | |
" for i in range(4,10,3):\n", | |
" print('cake')\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "h3lIeRmP5pbC" | |
}, | |
"source": [ | |
"Q: Output of the following code\n", | |
"\n", | |
" l = [10,20,50,70]\n", | |
" l.append(50)\n", | |
" l.remove(50)\n", | |
" print(l)\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "zQ9X5Zmc5rBq" | |
}, | |
"source": [ | |
"Q: What is the output of the following code?\n", | |
"\n", | |
" sampleList = [\"Jon\", \"Kelly\", \"Jessa\"]\n", | |
" sampleList.append(2, \"Scott\")\n", | |
" print(sampleList)\n", | |
"- The program executed with errors\n", | |
"- [‘Jon’, ‘Kelly’, ‘Scott’, ‘Jessa’]\n", | |
"- [‘Jon’, ‘Kelly’, ‘Jessa’, ‘Scott’]\n", | |
"- [‘Jon’, ‘Scott’, ‘Kelly’, ‘Jessa’]\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "0mhMln8t56bb" | |
}, | |
"source": [ | |
"Q: Output of the following code?\n", | |
"\n", | |
" for i in [2,5,7,9]:\n", | |
" j = i + 10\n", | |
" k = j + 20\n", | |
" print(k)\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "sfp1866Q57mj" | |
}, | |
"source": [ | |
"Q: What is the Output of the following code?\n", | |
"\n", | |
" for x in range(0.5, 5.5, 0.5):\n", | |
" print(x)\n", | |
"- [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5]\n", | |
"- [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]\n", | |
"- error\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "uRSjMGkp6C8L" | |
}, | |
"source": [ | |
"Q: Biggest number that will be printed from the following code is?\n", | |
"\n", | |
" for i in [5,10,15,20,25]:\n", | |
" for j in [0, 100, 1]:\n", | |
" print(i*j)\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "KPXBLGmkjx7C" | |
}, | |
"source": [ | |
"Q: How many times will 'canada' be printed?\n", | |
"\n", | |
" for i in [5,10,15,20,25]:\n", | |
" for j in [0, 1, 100]:\n", | |
" print('canada')\n", | |
"\n", | |
"\n", | |
"\n", | |
" " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "5qUXHM5W6FPr" | |
}, | |
"source": [ | |
"Q: Output of the following code? (think)\n", | |
"\n", | |
" for i in [[1,2,3],[4,5,6],[7,8,9]]:\n", | |
" for j in i:\n", | |
" print(j)\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "yl0mugE19Pvc" | |
}, | |
"source": [ | |
"Q: Items are accessed by their position in a dictionary and All the keys in a dictionary must be of the same type.\n", | |
"\n", | |
"- True\n", | |
"- False" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "04hoRXgBo-u9" | |
}, | |
"source": [ | |
"Q: Select the correct way to print Emma’s age.\n", | |
"\n", | |
" student = {1: {'name': 'Emma', 'age': '27', 'sex': 'Female'},\n", | |
" 2: {'name': 'Mike', 'age': '22', 'sex': 'Male'}}\n", | |
"- student[0][1]\n", | |
"- student[1][“age”]\n", | |
"- student[0][“age”]\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "MpW1AAYFlR6Q" | |
}, | |
"source": [ | |
"Q: How many times will 'candy' be printed?\n", | |
"\n", | |
" i = 10\n", | |
" while(i>5):\n", | |
" print('candy')\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "S3im4UjF9Oqc" | |
}, | |
"source": [ | |
"Q: What is the output of the following code\n", | |
"\n", | |
" dict1 = {\"key1\":1, \"key2\":2}\n", | |
" dict2 = {\"key2\":2, \"key1\":1}\n", | |
" print(dict1 == dict2)\n", | |
" \n", | |
"- True\n", | |
"- False\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "cbDN9hiM6mFo" | |
}, | |
"source": [ | |
"Q: How many times will 'candy' be printed?\n", | |
"\n", | |
" i = 5\n", | |
" while(i <= 15):\n", | |
" i = i + 3\n", | |
" print('candy') \n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "0MznwAOu6qIr" | |
}, | |
"source": [ | |
"Q: How many times will 'candy' be printed?\n", | |
"\n", | |
" i = 5\n", | |
" while(i != 15):\n", | |
" print('candy') \n", | |
" i = 15\n", | |
" \n", | |
"\n", | |
"\n", | |
"\n", | |
" \n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "WW9tQSTz6rcU" | |
}, | |
"source": [ | |
"Q: How many times will 'candy' be printed?\n", | |
"\n", | |
" i = 5\n", | |
" while(i != 15):\n", | |
" print('candy') \n", | |
" i = i + 3\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "kTVKwZQnovE-" | |
}, | |
"source": [ | |
"Q: \n", | |
"\n", | |
" i = 0\n", | |
" while(i < 100):\n", | |
" i = i + 5\n", | |
" break\n", | |
" print(i)\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "9HXwLzhN6Xrc" | |
}, | |
"source": [ | |
"Q: \n", | |
"\n", | |
" i = 0\n", | |
" while(i < 100):\n", | |
" i = i + 5\n", | |
" if(i == 1000):\n", | |
" break\n", | |
" print(i)\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "BBbzGeBR6YhL" | |
}, | |
"source": [ | |
"\n", | |
"\n", | |
"Q:\n", | |
"\n", | |
" my_sum = 0\n", | |
" for i in range(20,2):\n", | |
" if(i%5):\n", | |
" continue\n", | |
" my_sum += i\n", | |
" print(my_sum)\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "tSXjPYbB61XN" | |
}, | |
"source": [ | |
"Q: \n", | |
"\n", | |
" my_sum = 0\n", | |
" for i in range(20,2):\n", | |
" if(i%5):\n", | |
" continue\n", | |
" elif(i%10):\n", | |
" break\n", | |
" my_sum += i\n", | |
" print(my_sum)\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "VM8Wg43b7UZi" | |
}, | |
"source": [ | |
"*Q) Write a code that will, take input from the user and reverse the input:\n", | |
"\n", | |
"Bonus points for doing it in a single line of code\n", | |
"\n", | |
"\n", | |
" Example:\n", | |
" if input is 'hello'\n", | |
" then output should be \"olleh\"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Qg24dGUM6GhL" | |
}, | |
"source": [ | |
" \n", | |
"Q*: Print the sum of each individual list in the nested list\n", | |
" \n", | |
" [[1,2,3],[4,5,6],[7,8,9]]\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Q3OoKF4d-C1M" | |
}, | |
"source": [ | |
"Q*: Print the sum of each coloums, e.g. 1+4+6\n", | |
" \n", | |
" [[1,2,3],[4,5,6],[7,8,9]]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "NOZLz2Ly4h4a" | |
}, | |
"source": [ | |
"Q*: Given a number write a python code to find the indvidual digtis of a 4 digit number starting from the one's digit. (dont use strings)\n", | |
"\n", | |
" Example: 7348\n", | |
"\n", | |
"Your output should be:\n", | |
"\n", | |
" 8\n", | |
" 4\n", | |
" 3\n", | |
" 7" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "eRxJBeTdCaEK" | |
}, | |
"source": [ | |
"Q: Output of the following code\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Rc2g8e0sCaXo" | |
}, | |
"source": [ | |
"result = []\n", | |
"for i in ['a','b','c']:\n", | |
" for j in ['d','e','f']:\n", | |
" for k in ['g','h','i']:\n", | |
" result.append(i+j+k)\n", | |
"print(result[7])" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "HL8YgFWZ_-YW" | |
}, | |
"source": [ | |
"# Higher order thinking skills (HOTS)\n", | |
"\n", | |
"This question can be a little initmidating, but you have the python skills required to solve this question, the only thing you need to develop is the logic. Dont worry if you are not able to solve it.\n", | |
"\n", | |
"*Q: write a code to multiply two matrices \n", | |
"\n", | |
"Hint: First properly understand how we do it on paper then only move to coding it. [Matrix multiplication explained](https://youtu.be/n8ICyS8CKIQ/)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "IBLnWqe2_u_v" | |
}, | |
"source": [ | |
"# Homework\n", | |
"\n", | |
"Q1: Read about functions\n", | |
"\n", | |
"Q2: Try to code the matrix multiplication on your own, dont memorise but try to understand it. If you are having difficulties, use google, use youtube.\n", | |
"\n", | |
"Q3: Try to write a code for multiplying 2 compatible matrices (not necessarily square)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "E1ur4J_0bTDi" | |
}, | |
"source": [ | |
"# Program to multiply two matrices using nested loops\n", | |
"\n", | |
"# 3x3 matrix\n", | |
"X = [[12,7,3],\n", | |
" [4 ,5,6],\n", | |
" [7 ,8,9]]\n", | |
"# 3x3 matrix\n", | |
"Y = [[5,8,1],\n", | |
" [6,7,3],\n", | |
" [4,5,9]]\n", | |
"# result is 3x3\n", | |
"result = [[0,0,0],\n", | |
" [0,0,0],\n", | |
" [0,0,0]]\n", | |
"n = 3\n", | |
"\n", | |
"\n" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment