{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Python-Quiz-3.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyM/Qu7TbGCer7NFgPgTuiss",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dTrLdq0JuBaP"
},
"source": [
"# **Python Basics - Quiz-3**\r\n",
"\r\n",
"## **Use this to enhance to your python skill**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Wo-eRv2ZuGYm"
},
"source": [
"### **1) What is the output of the below code**\r\n",
"1. 2019\r\n",
"2. 39\r\n",
"3. 20 19\r\n",
"4. None of the above"
]
},
{
"cell_type": "code",
"metadata": {
"id": "J7BLSbSQuCsV"
},
"source": [
"'''\r\n",
"Program: 1\r\n",
"Description: Playing with strings using \"+\"\r\n",
"Author: Tanu Nanda Prabhu\r\n",
"'''\r\n",
"\r\n",
"value = 20\r\n",
"value2 = 19\r\n",
"\r\n",
"result = int('%d%d' % (value, value2))\r\n",
"print(result)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "JMYIbJwa1X0R"
},
"source": [
"### **2) What is the output of the below code**\r\n",
"1. 2020\r\n",
"2. 40\r\n",
"3. 20 20\r\n",
"4. None of the above"
]
},
{
"cell_type": "code",
"metadata": {
"id": "RckEQBTp1YlO"
},
"source": [
"'''\r\n",
"Program: 2\r\n",
"Description: Playing with strings using \"+\"\r\n",
"Author: Tanu Nanda Prabhu\r\n",
"'''\r\n",
"\r\n",
"value = '20'\r\n",
"value2 = '20'\r\n",
"\r\n",
"result = (int(value) + int(value2))\r\n",
"print(result)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "1doH8ODTzrog"
},
"source": [
"### **3) What is the output of the below code**\r\n",
"1. 65\r\n",
"2. 97\r\n",
"3. Invalid Syntax\r\n",
"4. None of the above"
]
},
{
"cell_type": "code",
"metadata": {
"id": "422UQhH4ztsb"
},
"source": [
"'''\r\n",
"Program: 3\r\n",
"Description: Playing with characters\r\n",
"Author: Tanu Nanda Prabhu\r\n",
"'''\r\n",
"\r\n",
"char = 'A'\r\n",
"print(ord(char))"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "eYmcuP3ZvEa9"
},
"source": [
"### **4) What is the output of the below code**\r\n",
"1. abc1abc2abc3\r\n",
"2. 1abc2abc3\r\n",
"3. Invalid Syntax\r\n",
"4. None of the above"
]
},
{
"cell_type": "code",
"metadata": {
"id": "K5iOlAAAvF-0"
},
"source": [
"'''\r\n",
"Program: 4\r\n",
"Description: Playing with join method\r\n",
"Author: Tanu Nanda Prabhu\r\n",
"'''\r\n",
"\r\n",
"s1 = 'abc'\r\n",
"s2 = '123'\r\n",
"print(s1.join(s2))"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "oxiiSN25A6nx"
},
"source": [
"### **5) What is the output of the below code**\r\n",
"1. True\r\n",
"2. False\r\n",
"3. Invalid Syntax\r\n",
"4. None of the above"
]
},
{
"cell_type": "code",
"metadata": {
"id": "UYGj4U3MA7ql"
},
"source": [
"'''\r\n",
"Program: 5\r\n",
"Author: Tanu Nanda Prabhu\r\n",
"'''\r\n",
"\r\n",
"str1, str2 = \"Python\", \"Python\"\r\n",
"\r\n",
"print(\"id of str1 is: \", id(str1))\r\n",
"print(\"id of str2 is: \", id(str2))\r\n",
"\r\n",
"if id(str1) == id(str2):\r\n",
" print(\"True\")\r\n",
"else:\r\n",
" print(\"False\")"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "tpG4KQUvWe-0"
},
"source": [
"\r\n",
"\r\n",
"---\r\n",
"\r\n",
"\r\n",
"### **6) What is the output of the below code**\r\n",
"1. ``\r\n",
"2. `<'set'>`\r\n",
"3. `set`\r\n",
"4. None of the above\r\n",
"\r\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "lEbdKfs6WjEu"
},
"source": [
"'''\r\n",
"Program: 6\r\n",
"Author: Tanu Nanda Prabhu\r\n",
"'''\r\n",
"\r\n",
"val = set()\r\n",
"print(type(val))"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "P-NRVKgUiO_6"
},
"source": [
"\r\n",
"\r\n",
"---\r\n",
"\r\n",
"\r\n",
"### **7) What is the output of the below code**\r\n",
"1. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\r\n",
"2. [7, 9, 11, 13, 15]\r\n",
"3. Lists cannot be added\r\n",
"4. None of the above\r\n",
"\r\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "CnzlXrCch8Ik"
},
"source": [
"'''\r\n",
"Program: 7\r\n",
"Author: Tanu Nanda Prabhu\r\n",
"'''\r\n",
"\r\n",
"# Playing with Lists in Python\r\n",
"\r\n",
"lis = [1, 2, 3, 4, 5]\r\n",
"lis2 = [6, 7, 8, 9, 10]\r\n",
"\r\n",
"print(lis+lis2)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "V6LdTLqz_gwQ"
},
"source": [
"\r\n",
"\r\n",
"---\r\n",
"\r\n",
"\r\n",
"### **8) What is the output of the below code**\r\n",
"1. True\r\n",
"2. False\r\n",
"3. Invalid Syntax\r\n",
"4. None of the above\r\n",
"\r\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Y6BQNgeO-vdW"
},
"source": [
"'''\r\n",
"Program: 8\r\n",
"Description: Using str.lower() method\r\n",
"Author: Tanu Nanda Prabhu\r\n",
"'''\r\n",
"\r\n",
"str1 = \"pythoN\"\r\n",
"str2 = str1.lower()\r\n",
"print(str1 == str2)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "f3ckANrOUJEC"
},
"source": [
"\r\n",
"\r\n",
"\r\n",
"\r\n",
"\r\n",
"---\r\n",
"\r\n",
"\r\n",
"### **9) What is the output of the below code**\r\n",
"1. `['P', 'y', 't', 'h', 'o', 'n'] `\r\n",
"2. `['P', 'y', 't', 'h', 'o', 'n'] `\r\n",
"3. `Python `\r\n",
"4. `Python `\r\n",
"\r\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "EabI5zplbBq3"
},
"source": [
"'''\r\n",
"Program: 9\r\n",
"Description: Typecasting the variable\r\n",
"Author: Tanu Nanda Prabhu\r\n",
"'''\r\n",
"\r\n",
"val = \"Python\"\r\n",
"\r\n",
"result = ''.join(list(val))\r\n",
"print(result, type(result))"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "x2MY8g_afHrX"
},
"source": [
"---\r\n",
"\r\n",
"### **10) What is the output of the below code**\r\n",
"1. 3\r\n",
"2. 6\r\n",
"3. 0\r\n",
"4. `Invalid Syntax - Index Can't be Multiplied`\r\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "dKxhCZbPelXl"
},
"source": [
"'''\r\n",
"Program: 10\r\n",
"Description: List index method\r\n",
"Author: Tanu Nanda Prabhu\r\n",
"'''\r\n",
"\r\n",
"lis = ['Python', 'Programming', 'Rocks'] \r\n",
"pos = lis.index(\"Rocks\") \r\n",
"print(pos * 3)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "zSbFiCEQfiy1"
},
"source": [
"\r\n",
"\r\n",
"---\r\n",
"\r\n"
]
}
]
}