We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 17
{
"cells": [ { "cell_type": "markdown", "id": "334efa46-c470-4473-a293-5b8fb3dd9e12", "metadata": {}, "source": [ "***Q1. Using Python script as a calculator Create the variables n, r, p and assign them values 10, 5, and 100 respectively. Then evaluate the following expression in the Python console. 𝐴 = 𝑝 (1 + 𝑟/ 100)n***" ] }, { "cell_type": "code", "execution_count": 1, "id": "2ab6ba09-8196-4fd4-943e-ba04c8440185", "metadata": {}, "outputs": [], "source": [ "n,r,p=10,5,100" ] }, { "cell_type": "code", "execution_count": 2, "id": "6fb4ec84-9d54-492b-a375-1f9a6923e9e9", "metadata": {}, "outputs": [], "source": [ "a = p*((1+(r/100))**n) " ] }, { "cell_type": "code", "execution_count": 3, "id": "9621d0c9-a09b-4eb3-84ff-33be312f4626", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "162.8894626777442\n" ] } ], "source": [ "print(a)" ] }, { "cell_type": "markdown", "id": "148fc1c6-94d7-4ff9-94dc-1b4b2d694937", "metadata": {}, "source": [ "***Ans: b. 162.89***" ] }, { "cell_type": "markdown", "id": "d16350f0-1cc3-4ff2-81c2-80f2a21475f1", "metadata": {}, "source": [
"***############################################################################### ########################################***" ] }, { "cell_type": "markdown", "id": "b07e0d68-d38d-40c4-a23c-5d2d71b7d1a7", "metadata": {}, "source": [ "***Q2. In a given string format operation, how will you print the given string.\n", "A = 10\n", "B = 20\n", "Str = \"There are {} students in the class, with {} who play at least one spor***t.\"" ] }, { "cell_type": "code", "execution_count": 15, "id": "6bc07b6e-6252-4aa5-a613-bfb6e4a24434", "metadata": {}, "outputs": [], "source": [ "A = 10\n", "B = 20\n", "Str = \"There are {} students in the class, with {} who play at least one sport.\"" ] }, { "cell_type": "code", "execution_count": 16, "id": "65f287bb-1c57-46d9-a781-064edcaf22f7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are 20 students in the class, with 10 who play at least one sport.\n" ] } ], "source": [ "print(Str.format(B,A))" ] }, { "cell_type": "markdown", "id": "92b67b4e-decc-44bc-9ebe-902fb41ac314", "metadata": {}, "source": [ "***Ans : c. print(string.format(b,a))***" ] }, { "cell_type": "markdown", "id": "ea622928-0fe2-42aa-9610-89959f7952e2", "metadata": {}, "source": [
"***############################################################################### ########################################***" ] }, { "cell_type": "markdown", "id": "db6c777b-c4d4-455e-adaf-7f2a52c0165c", "metadata": {}, "source": [ "***Q3. In a given sample string, How do you print a double quoted string in between a\n", "regular\n", "string using the escape character?\n", "Sample output = It goes without saying, “Time is Money”, and none can deny it.***" ] }, { "cell_type": "code", "execution_count": 19, "id": "85093f81-0bca-4e0d-b3b8-85406079f38a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "It goes without saying, \"Time is Money\", and none can deny it.\n" ] } ], "source": [ "print (\"It goes without saying, \\\"Time is Money\\\", and none can deny it.\")" ] }, { "cell_type": "markdown", "id": "572a8db0-b97e-4397-a850-ff7b108fdaa5", "metadata": {}, "source": [ "***Ans: a. print(“It goes without saying, \\“Time is Money\\”, and none can deny it.”)***" ] }, { "cell_type": "markdown", "id": "3f33fa5d-d8e7-4d20-9a33-7326d0bfb384", "metadata": {}, "source": [ "***############################################################################### ########################################***" ] }, { "cell_type": "markdown", "id": "07829002-b54d-4bf4-98c2-4cd8fa517ed9", "metadata": {}, "source": [ "***Q4. What will be the output of the following code?\n", "x = lambda a,b: a//b\n", "x(10,3)***" ] }, { "cell_type": "code", "execution_count": 20, "id": "60f33102-d882-49ed-bcf7-d456644231e3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x=lambda a,b: a//b\n", "x(10,3)" ] }, { "cell_type": "markdown", "id": "6f1d26f7-dbe0-46ad-87c4-9ab10878a5a2", "metadata": {}, "source": [ "***Ans : b. 3***" ] }, { "cell_type": "markdown", "id": "8ca0bd21-de98-4ae2-bf14-301c9121929f", "metadata": {}, "source": [
"***############################################################################### ########################################***" ] }, { "cell_type": "markdown", "id": "6314d61f-b61a-485e-922a-7fe1b6e53e42", "metadata": {}, "source": [ "***Q5. What will be the output of the following code?\n", "A = 10\n", "B = 12\n", "print(\"Smaller\") if A == B else print(\"Greater\") if A < B else print(\"True\")***" ] }, { "cell_type": "code", "execution_count": 23, "id": "41ddaac0-3da6-446f-9894-f23711b0e875", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Greater\n" ] } ], "source": [ "A = 10\n", "B = 12\n", "print(\"Smaller\") if A == B else print(\"Greater\") if A < B else print(\"True\")" ] }, { "cell_type": "markdown", "id": "8834bb05-d859-4c38-9514-160bb2cb7635", "metadata": {}, "source": [ "***Ans : c. Greater***" ] }, { "cell_type": "markdown", "id": "eca78944-05e8-430d-9a0a-7507b40bee63", "metadata": {}, "source": [
"***############################################################################### ########################################***" ] }, { "cell_type": "markdown", "id": "59cce116-06e1-47ce-af02-ecb3ff1917cb", "metadata": {}, "source": [ "***Q10.A Python NameError exception is raised when: -\n", "a. Trying to access a variable which has not been defined\n", "b. Trying to access a key in a dictionary that does not exis\n", "c. Accessing a column with misspelled column name\n", "d. Accessing the function from a module that has not been importe*****" ] }, { "cell_type": "markdown", "id": "91340cd5-9d69-453f-a596-61c6f956149e", "metadata": {}, "source": [ "***Ans : a. Trying to access a variable which has not been defined***" ] }, { "cell_type": "markdown", "id": "6df95c67-2cda-4386-afa6-40b4a9873ed0", "metadata": {}, "source": [
"***############################################################################### ########################################***" ] }, { "cell_type": "markdown", "id": "76dbee14-9511-46a3-9222-168625f0aba8", "metadata": {}, "source": [ "***Q11.What type of exception will be raised for the code given below? x = \"string\" int(x)***" ] }, { "cell_type": "code", "execution_count": 1, "id": "d579816e-9ef0-40b9-907a-48808defa115", "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "invalid literal for int() with base 10: 'string'", "output_type": "error", "traceback": [ "\ u001b[1;31m------------------------------------------------------------------------ ---\u001b[0m", "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[1], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m x \ u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstring\ u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m----> 2\u001b[0m \ u001b[38;5;28mint\u001b[39m (x)\n", "\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: 'string'" ] } ], "source": [ "x = \"string\"\n", "int (x)" ] }, { "cell_type": "markdown", "id": "c3bda3b4-0f17-489b-bd1f-92df131ae53f", "metadata": {}, "source": [ "***Ans : c. ValueError***" ] }, { "cell_type": "markdown", "id": "8f3ff775-5e85-405f-8de3-e03b18d01963", "metadata": {}, "source": [
"***############################################################################### ########################################***" ] }, { "cell_type": "markdown", "id": "a80ef0ff-9852-4232-9bad-d1c3c178b824", "metadata": {}, "source": [ "***Q12.A FileNotFoundError exception is raised by operating system errors when: -\n", "a. Trying to create a file or directory which already exists\n", "b. A file or directory is requested but does not exist in the working directory\n", "c. Trying to run an operation without the adequate access rights\n", "d. A directory operation, os.listdir() is requested on something which is not a\n", "dire***ctory" ] }, { "cell_type": "markdown", "id": "825b9cff-7408-43b8-810c-171409c5f7c9", "metadata": {}, "source": [ "***Ans : b. A file or directory is requested but does not exist in the working directory***" ] }, { "cell_type": "markdown", "id": "c16fbe4b-c0ef-45af-8fbb-ceb20ca08705", "metadata": {}, "source": [
"***############################################################################### ########################################***" ] }, { "cell_type": "markdown", "id": "6f33247a-6d87-4a00-986d-d9cb0ada3472", "metadata": {}, "source": [ "***Q13.Consider a variable Z. The value of Z is \"ID-5632\". Data type of Z is: -\n", "a. Complex\n", "b. Character\n", "c. Integer\n", "d. Boo***lean" ] }, { "cell_type": "code", "execution_count": 4, "id": "4ba225a1-3f5a-49eb-b69d-e4e0eaa95252", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "str" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Z=\"ID-5632\"\n", "type (Z)" ] }, { "cell_type": "markdown", "id": "89da0c68-cf3e-4db5-b449-a329577f5680", "metadata": {}, "source": [ "***Ans : b. Character***" ] }, { "cell_type": "markdown", "id": "49af842e-f63c-4f92-988f-1a7c32841f2f", "metadata": {}, "source": [
"***############################################################################### ########################################***" ] }, { "cell_type": "markdown", "id": "83551dbe-d76b-4393-b68e-52764dce5d09", "metadata": {}, "source": [ "***Q14.Which of the following variable(s) are character data type?\n", "a. K= “4”\n", "b. J= “Welcome”\n", "c. L= “?”\n", "d. All of the above***" ] }, { "cell_type": "markdown", "id": "5eb04551-7228-4785-b90b-acf18161f6ac", "metadata": {}, "source": [ "***Ans : d. All of the above***" ] }, { "cell_type": "markdown", "id": "7674ce23-163d-4714-b618-efaffb6b8f1a", "metadata": {}, "source": [
"***############################################################################### ########################################***" ] }, { "cell_type": "markdown", "id": "f486361d-7a36-4362-a8dd-6203892f91a6", "metadata": {}, "source": [ "***Q15.Choose the symbol/s that does not have the ability to convert any values to string?***\n", "a. ( )\n", "b. “ ”\n", "c. {}\n", "d. #" ] }, { "cell_type": "markdown", "id": "9a79e77b-7c47-4fef-a1d9-8216376f80b2", "metadata": {}, "source": [ "***Ans : c. {} d. #***" ] }, { "cell_type": "markdown", "id": "f457a55d-4f11-4298-930c-36e23d06f537", "metadata": {}, "source": [
"***############################################################################### ########################################***" ] }, { "cell_type": "markdown", "id": "c6f12dde-b0f3-476f-8956-207089f6bc0c", "metadata": {}, "source": [ "***Q16.Create a dictionary ‘Country’ that maps the following countries to their capitals\n", "respectively:\n", "Country India China Japan Qatar France\n", "State Delhi Beijing Tokyo Doha Marseilles\n", "Find 2 commands to replace “Marseilles” with “Paris”*** is:" ] }, { "cell_type": "code", "execution_count": 8, "id": "b622789f-8c56-4df2-8572-c94a00f4a3d5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'India': 'Delhi', 'China': 'Beijing', 'Japan': 'Tokyo', 'Qatar': 'Doha', 'France': 'Marseilles'}\n", "{'India': 'Delhi', 'China': 'Beijing', 'Japan': 'Tokyo', 'Qatar': 'Doha', 'France': 'Paris'}\n", "{'India': 'Delhi', 'China': 'Beijing', 'Japan': 'Tokyo', 'Qatar': 'Doha', 'France': 'Paris'}\n" ] } ], "source": [