{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "Python-Quiz-2.ipynb", "provenance": [], "collapsed_sections": [], "authorship_tag": "ABX9TyNii4wqrlRrcrdwe1t9wlTX", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "m19wGHCDy4cI" }, "source": [ "# **Python Basics - Quiz-2**\n", "\n", "## **Use this to enhance to your python skill**" ] }, { "cell_type": "markdown", "metadata": { "id": "NrLPKFeYy7H8" }, "source": [ "### **1) What is the output of the below code**\n", "1. p\n", "2. r\n", "3. o\n", "4. None of the above" ] }, { "cell_type": "code", "metadata": { "id": "YbwWPoh1yTM9" }, "source": [ "'''\n", "Program: 1\n", "Description: Finding the minimum string value\n", " This can be done using the min() along with a value\n", "Author: Tanu Nanda Prabhu\n", "'''\n", "\n", "# Calling the mini() function by passing the string value\n", "minimum = min(\"programming\")\n", "print(minimum)" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "U5rLUVOrDT6m" }, "source": [ "### **2) What is the output of the below code**\n", "1. p\n", "2. y\n", "3. t\n", "4. None of the above" ] }, { "cell_type": "code", "metadata": { "id": "pL9shtJWDVd1" }, "source": [ "'''\n", "Program: 2\n", "Description: Finding the maximum string value\n", " This can be done using the max() along with a value\n", "Author: Tanu Nanda Prabhu\n", "'''\n", "\n", "# Calling the max() function by passing the string value\n", "maximum = max(\"python\")\n", "print(maximum)" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "armkk8YfAvkh" }, "source": [ "### **3) What is the output of the below code**\n", "1. Success\n", "2. Failure\n", "3. Invalid Syntax\n", "4. None of the above" ] }, { "cell_type": "code", "metadata": { "id": "56pUyW7_BBJL" }, "source": [ "'''\n", "Program: 3\n", "Description: Playing with '+' and increment operators in Python\n", "Author: Tanu Nanda Prabhu\n", "'''\n", "\n", "a = 7\n", "a1 = a + 1\n", "a2 = a++\n", "\n", "if a1 == a2:\n", " print(\"Success\")\n", "else:\n", " print(\"Failure\")\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "GCCX3cZg0fZj" }, "source": [ "### **4) What is the output of the below code**\n", "1. Success\n", "2. Failure\n", "3. Invalid Syntax\n", "4. None of the above" ] }, { "cell_type": "code", "metadata": { "id": "rue6_C0PzE2P" }, "source": [ "'''\n", "Program: 4\n", "Description: Playing with increment and decrement operators in Python\n", "Author: Tanu Nanda Prabhu\n", "'''\n", "\n", "a = 7\n", "a1 = 0\n", "a2 = 0\n", "a1 += 1\n", "a2 -= 1\n", "\n", "if a1 == a2:\n", " print(\"Success\")\n", "else:\n", " print(\"Failure\")\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "9bdahV4t-PIf" }, "source": [ "### **5) What is the output of the below code**\n", "1. a a a\n", "2. a1 a2 a3\n", "3. 1 2 3\n", "4. None of the above" ] }, { "cell_type": "code", "metadata": { "id": "RpZ2dMgd-Nim" }, "source": [ "'''\n", "Program: 5\n", "Description: Performing list operations\n", " \n", "Author: Tanu Nanda Prabhu\n", "'''\n", "\n", "l = {'a1':\"1\", 'a2': \"2\", 'a3':\"3\"}\n", "for x, y in l:\n", " print(x[0], end = \" \")" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "fngzOp_mclgr" }, "source": [ "\n", "\n", "---\n", "\n", "\n", "\n", "### **6) What is the output of the below code**\n", "1. a a a\n", "2. a1 a2 a3\n", "3. 1 2 3\n", "4. None of the above" ] }, { "cell_type": "code", "metadata": { "id": "wzh-fAcFcZFX" }, "source": [ "'''\n", "Program: 6\n", "Description: Performing list operations\n", " \n", "Author: Tanu Nanda Prabhu\n", "'''\n", "\n", "l = {'a1':\"1\", 'a2': \"2\", 'a3':\"3\"}\n", "for x in l:\n", " print(x[1], end = \" \")" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "L1L3zuaUcrRH" }, "source": [ "\n", "\n", "\n", "---\n", "\n", "\n", "\n", "### **7) What is the output of the below code**\n", "1. a a a\n", "2. a1 a2 a3\n", "3. 1 2 3\n", "4. None of the above" ] }, { "cell_type": "code", "metadata": { "id": "8NEadcp4dzQz" }, "source": [ "'''\n", "Program: 7\n", "Description: Performing list operations\n", " \n", "Author: Tanu Nanda Prabhu\n", "'''\n", "\n", "l = {'a1':\"1\", 'a2': \"2\", 'a3':\"3\"}\n", "for x in l:\n", " print(x, end = \" \")" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "mo_7cfh60ZVP" }, "source": [ "---\n", "\n", "### **8) What is the output of the below code**\n", "1. e\n", "2. The\n", "3. T\n", "4. Invalid Index" ] }, { "cell_type": "code", "metadata": { "id": "imALsSVb0Yo0" }, "source": [ "'''\n", "Program: 8\n", "Description: Performing list operations using index\n", " \n", "Author: Tanu Nanda Prabhu\n", "'''\n", "\n", "l = [\"Every\", 1, \"Can't\", \"Be\", \"The\", \"Best\", 1]\n", "print(l[4][2])" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "jFqGfS6FM5EQ" }, "source": [ "\n", "\n", "---\n", "\n", "### **9) What is the output of the below code**\n", "1. 9\n", "2. 9.0\n", "3. 8.9\n", "4. Invalid Syntax\n", "\n" ] }, { "cell_type": "code", "metadata": { "id": "Rwf25sRVM9ER" }, "source": [ "'''\n", "Program: 9\n", "Description: Performing quick mathematics using Python\n", " \n", "Author: Tanu Nanda Prabhu\n", "'''\n", "\n", "value = 6/2*(1+2)\n", "print(value)" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "uEpO9d5MaWvP" }, "source": [ "\r\n", "\r\n", "---\r\n", "\r\n", "### **10) What is the output of the below code**\r\n", "1. 7\r\n", "2. 7.0\r\n", "3. 6\r\n", ".9\r\n", "4. Invalid Syntax\r\n", "\r\n" ] }, { "cell_type": "code", "metadata": { "id": "leL_YoDEZ_F0" }, "source": [ "'''\r\n", "Program: 10\r\n", "Description: Performing quick mathematics using eval\r\n", " \r\n", "Author: Tanu Nanda Prabhu\r\n", "'''\r\n", "\r\n", "value = ('1 + 3 * 2')\r\n", "print(eval(value))" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "f4BF_DYsc3B5" }, "source": [ "\r\n", "\r\n", "---\r\n", "\r\n" ] } ] }