diff --git a/Additional Python -Solutions.ipynb b/Additional Python -Solutions.ipynb new file mode 100644 index 0000000..8edf646 --- /dev/null +++ b/Additional Python -Solutions.ipynb @@ -0,0 +1,2563 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d0a11e6b", + "metadata": {}, + "source": [ + "# Assume Data wherever needed/necessary" + ] + }, + { + "cell_type": "markdown", + "id": "5a0e7bb1", + "metadata": {}, + "source": [ + "### Loop Statements" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4bcc8233", + "metadata": {}, + "outputs": [], + "source": [ + "# WAP stands for Write A Program" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47433a3c", + "metadata": {}, + "outputs": [], + "source": [ + "#L1 E\n", + "WAP to print all elements of a list using a for loop. \n", + "Take the elements of the list from the user.\n", + "\n", + "For e.g. Input: l = [3,'Hi',67,0,12,0,8]\n", + " Output: 3\n", + " 'Hi'\n", + " 67\n", + " 0\n", + " 12\n", + " 0\n", + " 8" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ef715ce8", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ece91ea2", + "metadata": {}, + "outputs": [], + "source": [ + "#L2 M\n", + "WAP to take inputs from user to make a list. Length of the list has to be taken from the user.\n", + "Again take one input from user and search it in the list and delete that element, if found.\n", + "If not found, print \"Element not present\".\n", + "\n", + "For e.g. Input: len_list = 5\n", + " list = [\"a\", \"b\", \"y\", \"e\", \"p\"]\n", + " search_element = \"g\"\n", + " Output: \"Element not found\"\n", + " search_element = \"e\"\n", + " Output: [\"a\", \"b\", \"y\", \"p\"]" + ] + }, + { + "cell_type": "markdown", + "id": "dc3ad564", + "metadata": {}, + "source": [ + "if element in list : \n", + " element found\n", + "else : \n", + " element not found" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cf5ae0f6", + "metadata": {}, + "outputs": [], + "source": [ + "len_list = int( input(\"How many elements : \") )\n", + "listName = []\n", + "for i in range( len_list ) : \n", + " elementName = input(\"Element Name: \")\n", + " listName.append(elementName)\n", + "print( listName )\n", + "\n", + "\n", + "search_element = input(\"Mention the element to be searched from the above list : \")\n", + "if search_element in listName : \n", + " print( \"element found\" )\n", + "else : \n", + " print( \"element not found\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fa2448e8", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1a65e214", + "metadata": {}, + "outputs": [], + "source": [ + "#L3 EM\n", + "Make a grading system for a school based on the marks of the students using the following criteria.\n", + "Marks 0 - 40 : Grade F\n", + " 41 - 50 : Grade E\n", + " 51 - 70 : Grade D\n", + " 71 - 80 : Grade C\n", + " 81 - 90 : Grade B\n", + " 91 - 100: Grade A\n", + "Continuously take marks as input from the user and print the grade. \n", + "The user can enter \"Stop\" to stop the loop." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "c66d6dba", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter mark or enter 'stop' to end the program: 65\n", + "mark: 65 | grade:D\n", + "Enter mark or enter 'stop' to end the program: 92\n", + "mark: 92 | grade:A\n", + "Enter mark or enter 'stop' to end the program: 2\n", + "mark: 2 | grade:F\n", + "Enter mark or enter 'stop' to end the program: stop\n" + ] + } + ], + "source": [ + "while True:\n", + " mark=input(\"Enter mark or enter 'stop' to end the program: \")\n", + " if (mark.strip().lower()==\"stop\"):\n", + " break\n", + " if 0<=int(mark)<=40:\n", + " grade=\"F\"\n", + " elif 41<=int(mark)<=50:\n", + " grade=\"E\"\n", + " elif 51<=int(mark)<=70:\n", + " grade=\"D\"\n", + " elif 71<=int(mark)<=80:\n", + " grade=\"C\" \n", + " elif 81<=int(mark)<=90:\n", + " grade=\"B\"\n", + " elif 91<=int(mark)<=100:\n", + " grade=\"A\"\n", + " else:\n", + " print(\"invalid input\")\n", + " print (f\"mark: {mark} | grade:{grade}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "62fde17e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fc106fff", + "metadata": {}, + "outputs": [], + "source": [ + "#L4 E\n", + "WAP to save the cube of all numbers from 1 to a number n in list, \n", + "where n is taken as input from the user.\n", + "\n", + "For e.g. Input: 5\n", + " Output: [1, 8, 27, 64, 125] #Cube of numbers from 1 to 5 where 5 is the input from the user" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "f224ef68", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter a number: 10\n", + "[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]\n" + ] + } + ], + "source": [ + "l4 = []\n", + "input4 = int(input(\"Enter a number: \"))\n", + "for i in range(1, input4+1):\n", + " l4.append(i**3)\n", + "print(l4)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "caf260cc", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e8e46444", + "metadata": {}, + "outputs": [], + "source": [ + "#L5 E\n", + "WAP to print even numbers in a given range in reverse order. Take the range from the user.\n", + "\n", + "For e.g. Input: start = 3\n", + " End = 14\n", + " Output: 14, 12, 10, 8, 6, 4" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "36f7dc9d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter start of range: 1\n", + "Enter end of range: 10\n", + "10 , 8 , 6 , 4 , 2 , " + ] + } + ], + "source": [ + "x5 = int(input(\"Enter start of range: \"))\n", + "y5 = int(input(\"Enter end of range: \"))\n", + "for i in range(y5, x5, -2):\n", + " print(i, end = \" , \")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "bbb4a6de", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter start: 1\n", + "Enter end: 10\n", + "[8, 6, 4, 2]\n" + ] + } + ], + "source": [ + "listName = [i for i in range ( int(input(\"Enter start: \")), int(input(\"Enter end: \")) ) if i%2==0]\n", + "print(listName[::-1])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3dde1337", + "metadata": {}, + "outputs": [], + "source": [ + "start=2\n", + "end=15\n", + "a=[]\n", + "b=[]\n", + "for i in reversed(range(start,end)):\n", + " if (i%2)==0:\n", + " a.append(i)\n", + "print(a)\n", + "for i in reversed(range(start,end)):\n", + " if (i%2)!=0:\n", + " b.append(i)\n", + "print(b)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e7b38c1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "656dccf5", + "metadata": {}, + "outputs": [], + "source": [ + "#L6 E\n", + "WAP to print odd numbers in a given range in reverse order.\n", + "Take the range from the user.\n", + "\n", + "For e.g. Input: start = 3\n", + " End = 14\n", + " Output: 13, 11, 9, 7, 5, 3" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "85302f61", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Even List : \n", + "[14, 12, 10, 8, 6, 4, 2]\n", + "Odd List : \n", + "[13, 11, 9, 7, 5, 3, 1]\n" + ] + } + ], + "source": [ + "start=1\n", + "end=15\n", + "a=[]\n", + "b=[]\n", + "for i in reversed(range(start,end)):\n", + " if (i%2)==0:\n", + " a.append(i)\n", + "print(\"Even List : \")\n", + "print(a)\n", + "for i in reversed(range(start,end)):\n", + " if (i%2)!=0:\n", + " b.append(i)\n", + "print(\"Odd List : \")\n", + "print(b)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f2c652b1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "658962f2", + "metadata": {}, + "outputs": [], + "source": [ + "#L7 E\n", + "WAP to print multiplication table of a number taken as input from the user.\n", + "\n", + "For e.g. Input: 5\n", + " Output: 5*1 = 5\n", + " 5*2 = 10\n", + " .\n", + " .\n", + " .\n", + " 5*10 = 50" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "efe039de", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "enter number::10\n", + "10 * 1 = 10\n", + "10 * 2 = 20\n", + "10 * 3 = 30\n", + "10 * 4 = 40\n", + "10 * 5 = 50\n", + "10 * 6 = 60\n", + "10 * 7 = 70\n", + "10 * 8 = 80\n", + "10 * 9 = 90\n", + "10 * 10 = 100\n" + ] + } + ], + "source": [ + "num=int(input(\"enter number::\"))\n", + "for i in range (1,11):\n", + "\n", + "# print(num,\"*\",i,\"=\",num*i)\n", + " print(f\"{num} * {i} = {num*i}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7ceb6281", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7695a07a", + "metadata": {}, + "outputs": [], + "source": [ + "#L8 E\n", + "WAP to print the following pattern.\n", + "\n", + "1\n", + "1 2\n", + "1 2 3\n", + "1 2 3 4" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "3bd81f7c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mention Upper Range : 4\n", + "1\n", + "2\n", + "3\n", + "4\n" + ] + } + ], + "source": [ + "number = int( input( \"Mention Upper Range : \" ) )\n", + "\n", + "for i in range(1, number + 1) : \n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "f803f00c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mention Upper Range : 4\n", + " i = 1 \n", + " j = 1 \n", + "******************************\n", + " i = 2 \n", + " j = 1 \n", + " j = 2 \n", + "******************************\n", + " i = 3 \n", + " j = 1 \n", + " j = 2 \n", + " j = 3 \n", + "******************************\n", + " i = 4 \n", + " j = 1 \n", + " j = 2 \n", + " j = 3 \n", + " j = 4 \n", + "******************************\n" + ] + } + ], + "source": [ + "number = int( input( \"Mention Upper Range : \" ) )\n", + "\n", + "for i in range(1, number + 1) : \n", + " print(f\" i = {i} \")\n", + " for j in range( 1, i + 1 ) : \n", + " print( f\" j = {j} \" )\n", + " print(\"*\" * 30)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "596d3506", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mention Upper Range : 4\n", + "1 \n", + "1 2 \n", + "1 2 3 \n", + "1 2 3 4 \n" + ] + } + ], + "source": [ + "number = int( input( \"Mention Upper Range : \" ) )\n", + "\n", + "for i in range(1, number + 1) : \n", + "# print(f\" i = {i} \")\n", + " for j in range( 1, i + 1 ) : \n", + "# print( f\" j = {j} \", end = \" \" )\n", + " print( j, end = \" \" )\n", + " print()\n", + "# print(\"*\" * 30)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "4ec45343", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mention Upper Range : 4\n", + "1 \n", + "1 2 \n", + "1 2 3 \n", + "1 2 3 4 \n" + ] + } + ], + "source": [ + "number = int( input( \"Mention Upper Range : \" ) )\n", + "for i in range(1, number + 1) : # 1 2 3 4 \n", + " for j in range( 1, i + 1 ) : \n", + " print( j, end = \" \" )\n", + " print()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a9a0128e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bd7a8149", + "metadata": {}, + "outputs": [], + "source": [ + "#L9 H\n", + "Write a program to calculate the sum of series up to n terms for a digit d. n & d are taken as input from the user.\n", + "\n", + "For example:\n", + " Input: n = 5, d = 2\n", + " Logic: 2 + 22 + 222 + 2222 + 22222 \n", + " Output: 24690" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d88795c6", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "3de2e1e1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter Digit (0 - 9) : 2\n", + " Mention n terms upto which SUM has to be done: 5\n", + "2\n", + "22\n", + "222\n", + "2222\n", + "22222\n", + "22222\n" + ] + } + ], + "source": [ + "d = int( input( \"Enter Digit (0 - 9) : \" ) )\n", + "n = int( input(\" Mention n terms upto which SUM has to be done: \") )\n", + "\n", + "totalSum = 0\n", + "for i in range(1, n + 1) : \n", + " number = str(d) * i\n", + " print(number)\n", + " totalSum = totalSum + int( number )\n", + " \n", + "print(totalSum)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "2b2af8c1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter Digit (0 - 9) : 2\n", + " Mention n terms upto which SUM has to be done: 5\n", + "2 + 22 + 222 + 2222 + 22222 \n", + "24690\n" + ] + } + ], + "source": [ + "d = int( input( \"Enter Digit (0 - 9) : \" ) )\n", + "n = int( input(\" Mention n terms upto which SUM has to be done: \") )\n", + "\n", + "totalSum = 0\n", + "pattern = \"\"\n", + "for i in range(1, n + 1) : \n", + " number = str(d) * i\n", + " pattern = pattern + number + \" + \"\n", + "# print(pattern)\n", + " totalSum = totalSum + int( number )\n", + " \n", + "print( pattern[ : len( pattern ) - 2 ] )\n", + "print(totalSum)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73dbe926", + "metadata": {}, + "outputs": [], + "source": [ + "d = int( input( \"Enter Digit (0 - 9) : \" ) )\n", + "n = int( input(\" Mention n terms upto which SUM has to be done: \") )\n", + "\n", + "totalSum = 0\n", + "pattern = \"\"\n", + "for i in range(1, n + 1) : \n", + " number = str(d) * i\n", + " pattern = pattern + number + \" + \"\n", + "# print(pattern)\n", + " totalSum = totalSum + int( number )\n", + "print(totalsum)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3008db54", + "metadata": {}, + "outputs": [], + "source": [ + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c39a09dd", + "metadata": {}, + "outputs": [], + "source": [ + "#L10 M\n", + "WAP that keeps on accepting numbers from the user until the user enters Zero(0) as input.\n", + "Display the sum and average of all the numbers.\n", + "\n", + "For example:\n", + " Input: 3, 6, 8, 2, 5, Stop\n", + " Output: Sum = 24\n", + " Average = 4.8" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "41bc7605", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mention Number : 10\n", + "Mention Number : 4\n", + "Mention Number : 6\n", + "Mention Number : -3\n", + "Mention Number : -8\n", + "Mention Number : 0\n", + "Total Sum = 9 \n", + "Average = 1.8\n" + ] + } + ], + "source": [ + "count = 0 # this is used to divide the totalSum\n", + "totalSum = 0\n", + "\n", + "while True : \n", + " \n", + " num = int( input(\"Mention Number : \") )\n", + " \n", + " if num == 0 :\n", + " print(f\"Total Sum = {totalSum} \\nAverage = {average}\" )\n", + " break\n", + " \n", + " totalSum = totalSum + num\n", + " count = count + 1\n", + " average = totalSum/count\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3fc09d62", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2ea40596", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dde14cda", + "metadata": {}, + "outputs": [], + "source": [ + "#L11 E\n", + "Accept n numbers from the user and display their average. n is input from the user.\n", + "\n", + "For example:\n", + " Input: n = 5\n", + " Numbers = 3, 6, 2, 9, 0\n", + " Output: Average = 4.0" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "7596f887", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Numbers5\n", + "numbers to calc average :6\n", + "numbers to calc average :-3\n", + "numbers to calc average :7\n", + "numbers to calc average :8\n", + "numbers to calc average :-2\n", + "[6, -3, 7, 8, -2]\n", + "Average of numbers is 3.2\n", + "Average of numbers is 3\n" + ] + } + ], + "source": [ + "n = int(input(\"Numbers\"))\n", + "\n", + "a =[]\n", + "\n", + "for i in range(n):\n", + " el = int(input(\"numbers to calc average :\"))\n", + " a.append(el)\n", + "print(a)\n", + "\n", + "add = sum(a)\n", + "#print (add)\n", + "avg = add/n\n", + "print(\"Average of numbers is\", avg)\n", + "print(\"Average of numbers is\", int(avg) )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "365faf9a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2908eb4", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "7c33883b", + "metadata": {}, + "source": [ + "### String Questions" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f3581a03", + "metadata": {}, + "outputs": [], + "source": [ + "#S1 E\n", + "Write a Python program to count the number of each of the characters (character frequency) \n", + " in a string input by the user. Ignore the case.\n", + " For example: Input: \"Python is great\"\n", + "\t\tOutput: P = 1, y = 1, t = 2, and so on..." + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "8d2e3882", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'P': 1,\n", + " 'y': 1,\n", + " 't': 2,\n", + " 'h': 1,\n", + " 'o': 1,\n", + " 'n': 1,\n", + " ' ': 2,\n", + " 'i': 1,\n", + " 's': 1,\n", + " 'g': 1,\n", + " 'r': 1,\n", + " 'e': 1,\n", + " 'a': 1}" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "Input = \"Python is great\"\n", + " \n", + "dt={}\n", + "for s in Input:\n", + " dt[s]=Input.count(s)\n", + "dt" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "92f76cf2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Character : P, Count => 1\n", + "Character : y, Count => 1\n", + "Character : t, Count => 2\n", + "Character : h, Count => 1\n", + "Character : o, Count => 1\n", + "Character : n, Count => 1\n", + "Character : , Count => 2\n", + "Character : i, Count => 1\n", + "Character : s, Count => 1\n", + "Character : , Count => 2\n", + "Character : g, Count => 1\n", + "Character : r, Count => 1\n", + "Character : e, Count => 1\n", + "Character : a, Count => 1\n", + "Character : t, Count => 2\n" + ] + } + ], + "source": [ + "Input = \"Python is great\"\n", + "\n", + "for i in Input : \n", + " print(f\"Character : {i}, Count => {Input.count(i)}\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "5978c9a9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[('n', 1),\n", + " ('e', 1),\n", + " ('a', 1),\n", + " ('P', 1),\n", + " ('h', 1),\n", + " ('i', 1),\n", + " ('t', 2),\n", + " ('s', 1),\n", + " ('y', 1),\n", + " ('r', 1),\n", + " ('g', 1),\n", + " ('o', 1),\n", + " (' ', 2)]" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Input = \"Python is great\"\n", + "\n", + "listName = []\n", + "for i in Input : \n", + "# print(f\"Character : {i}, Count => {Input.count(i)}\")\n", + " listName.append( (i, Input.count(i)) )\n", + "list( set( listName ) )\n" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "f541ad3f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[('P', 1),\n", + " ('y', 1),\n", + " ('t', 2),\n", + " ('h', 1),\n", + " ('o', 1),\n", + " ('n', 1),\n", + " (' ', 2),\n", + " ('i', 1),\n", + " ('s', 1),\n", + " ('g', 1),\n", + " ('r', 1),\n", + " ('e', 1),\n", + " ('a', 1)]" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Input = \"Python is great\"\n", + "\n", + "listName = []\n", + "for i in Input : \n", + "# print(f\"Character : {i}, Count => {Input.count(i)}\")\n", + " if (i, Input.count(i)) not in listName : \n", + " listName.append( (i, Input.count(i)) )\n", + "listName\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c35cebb6", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8d72e04f", + "metadata": {}, + "outputs": [], + "source": [ + "#S2 M\n", + "Write a Python program to find the digits which are absent in a given mobile number.\n", + "\n", + " For example: Input : 9354328855\n", + " Output: 0167" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "61600301", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'0167'" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Input = 9354328855\n", + "\n", + "finalString = \"\"\n", + "for i in range(10) : \n", + "# print(i, type(i))\n", + " if str(i) not in str(Input) : \n", + " finalString = finalString + str(i)\n", + "finalString" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "2c387e82", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "01\n", + "016\n", + "0167\n" + ] + }, + { + "data": { + "text/plain": [ + "'0167'" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Input = \"9354328855\"\n", + "\n", + "finalString = \"\"\n", + "for i in range(10) : \n", + "# print(i, type(i))\n", + " if str(i) not in Input : \n", + " finalString = finalString + str(i)\n", + "# print( finalString )\n", + "finalString" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "c0723a3a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 \n", + "1 \n", + "2 \n", + "3 \n", + "4 \n", + "5 \n", + "6 \n", + "7 \n", + "8 \n", + "9 \n" + ] + } + ], + "source": [ + "# Input = \"9354328855\"\n", + "\n", + "# finalString = \"\"\n", + "# for i in range(10) : \n", + "# print(i, type(i))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "961eb5b2", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "579e8d6c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c1d08d3e", + "metadata": {}, + "outputs": [], + "source": [ + "#S3 M\n", + "WAP in python to find average of n numbers taken as input from the user dynamically." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f72904f3", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2f4205dd", + "metadata": {}, + "outputs": [], + "source": [ + "#S4 E\n", + "WAP in python that accepts a hyphen-separated sequence of \n", + "words as input and prints the words in a hyphen-separated \n", + "sequence after sorting them alphabetically.\n", + "\n", + "For e.g. Input: \"p-y-t-h-o-n\"\n", + " Output: ['h', 'n','o', 'p', 't', 'y']" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "0730a6f8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['h', 'n', 'o', 'p', 't', 'y']" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Input = \"p-y-t-h-o-n\"\n", + "output = Input.split(\"-\")\n", + "sorted( output )\n" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "id": "2801e964", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# \"h\" < \"n\"" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "b559ed6a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "python\n", + "['h', 'n', 'o', 'p', 't', 'y']\n" + ] + } + ], + "source": [ + "Input = \"p-y-t-h-o-n\"\n", + "output = Input.replace(\"-\", \"\")\n", + "print( output )\n", + "print( sorted( output ) )\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "43af3e65", + "metadata": {}, + "outputs": [], + "source": [ + "# Anagrams : tea eat" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0e043246", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21535981", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "651e6590", + "metadata": {}, + "outputs": [], + "source": [ + "#S5 MH\n", + "WAP in python to find the number of vowels, consonants, digits, special \n", + "characters and white space characters in a string input by the user.\n", + "\n", + "Example: Input: \"Qwerty@123\"\n", + "\toutput: v = 1, c = 5, d = 3, w = 0, s = 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fd38ab8d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "300a41ed", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5a0f47dc", + "metadata": {}, + "outputs": [], + "source": [ + "#S6 MH\n", + "WAP in python to check the strength of the password input by the user based on the following features.\n", + " Length minimum of 8 characters (+1 Strength)\n", + " Combination of upper case & lower case characters (+1 Strength)\n", + " Combination of alphabets & digits (+1 Strength)\n", + " Use of Special Characters (+1 Strength)\n", + " \n", + "Example: Input: \"Qwerty@123\"\n", + " Output: Strength = 4" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "4b001219", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "1\n", + "1\n", + "1\n" + ] + }, + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s1, s2, s3 ,s4 = 0, 0, 0, 0\n", + "\n", + "Input = \"Qwerty@123\"\n", + "\n", + "if len(Input) > 8 : \n", + " s1 = 1\n", + " \n", + "if ( any( [s.islower() for s in Input] ) and ( any( [s.isupper() for s in Input] ) ) ) : \n", + " s2 = 1\n", + " \n", + "if ( any( [s.isdigit() for s in Input] ) and ( any( [s.isalpha() for s in Input] ) ) ) : \n", + " s3 = 1\n", + "\n", + "if ( any( [ not( s.isalnum() ) for s in Input] ) ) : \n", + " s4 = 1\n", + "\n", + "\n", + "print( s1 )\n", + "print( s2 )\n", + "print( s3 )\n", + "print( s4 )\n", + "\n", + "finalStrength = s1 + s2 + s3 + s4\n", + "finalStrength\n" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "id": "0219b2f7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "1\n", + "1\n", + "1\n" + ] + }, + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s1, s2, s3 ,s4 = 0, 0, 0, 0\n", + "\n", + "Input = \"PPyt*hon47\"\n", + "\n", + "if len(Input) > 8 : \n", + " s1 = 1\n", + " \n", + "if ( any( [s.islower() for s in Input] ) and ( any( [s.isupper() for s in Input] ) ) ) : \n", + " s2 = 1\n", + " \n", + "if ( any( [s.isdigit() for s in Input] ) and ( any( [s.isalpha() for s in Input] ) ) ) : \n", + " s3 = 1\n", + "\n", + "if ( any( [ not( s.isalnum() ) for s in Input] ) ) : \n", + " s4 = 1\n", + "\n", + "\n", + "print( s1 )\n", + "print( s2 )\n", + "print( s3 )\n", + "print( s4 )\n", + "\n", + "finalStrength = s1 + s2 + s3 + s4\n", + "finalStrength\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "de9f85d2", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a438e77e", + "metadata": {}, + "outputs": [], + "source": [ + "# Is there any digit inside the seq ??\n", + "\n", + "Input = \"Qwerty@123\"\n", + "for s in Input : \n", + " if s.isdigit() : \n", + " print(True)\n", + " else : \n", + " print(False)" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "305ff518", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[False, False, False, False, False, False, False, True, True, True]" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[s.isdigit() for s in Input]" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "3566481e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[True, True, True]\n", + "AND : True\n", + "OR : True\n" + ] + } + ], + "source": [ + "# AND (all) : return TRUE if every condition is TRUE\n", + "# OR (any) : return FALSE if every condition is FALSE\n", + "\n", + "\n", + "Input = \"123\"\n", + "print( [s.isdigit() for s in Input] )\n", + "print( \"AND : \", all( [s.isdigit() for s in Input] ) )\n", + "print( \"OR : \", any( [s.isdigit() for s in Input] ) )\n" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "8b24a6a4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[True, True, True, False, False, False]\n", + "AND : False\n", + "OR : True\n" + ] + } + ], + "source": [ + "# AND (all) : return TRUE if every condition is TRUE\n", + "# OR (any) : return FALSE if every condition is FALSE\n", + "\n", + "\n", + "Input = \"123a`ef\"\n", + "print( [s.isdigit() for s in Input] )\n", + "print( \"AND : \", all( [s.isdigit() for s in Input] ) )\n", + "print( \"OR : \", any( [s.isdigit() for s in Input] ) )\n" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "id": "d3542983", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[True, False, False, False]\n", + "AND : False\n", + "OR : True\n" + ] + } + ], + "source": [ + "# AND (all) : return TRUE if every condition is TRUE\n", + "# OR (any) : return FALSE if every condition is FALSE\n", + "\n", + "\n", + "Input = \"1aef\"\n", + "print( [s.isdigit() for s in Input] )\n", + "print( \"AND : \", all( [s.isdigit() for s in Input] ) )\n", + "print( \"OR : \", any( [s.isdigit() for s in Input] ) )\n" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "38965f99", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[False, False, False]\n", + "AND : False\n", + "OR : False\n" + ] + } + ], + "source": [ + "# AND (all) : return TRUE if every condition is TRUE\n", + "# OR (any) : return FALSE if every condition is FALSE\n", + "\n", + "\n", + "Input = \"aef\"\n", + "print( [s.isdigit() for s in Input] )\n", + "print( \"AND : \", all( [s.isdigit() for s in Input] ) )\n", + "print( \"OR : \", any( [s.isdigit() for s in Input] ) )\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ac247548", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a0ae02af", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f31c64b7", + "metadata": {}, + "outputs": [], + "source": [ + "#S7 E\n", + "WAP in python to compare two strings and tell the user if both of those strings are same or not. \n", + "Ignore their case.\n", + "\n", + "Example: Input String1: \"Hello\"\n", + "\tInput String2: \"hello\"\n", + "\tOutput: Strings are same" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3e03fb0d", + "metadata": {}, + "outputs": [], + "source": [ + "#S8 E\n", + "WAP in python to calculate the number of times a character is repeated in a given string.\n", + "Take the string and character from the user.\n", + "\n", + "Example: Input String: \"Neil Nitin Mukesh\"\n", + " Input Character: \"e\"\n", + " Output: 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb9d9a4d", + "metadata": {}, + "outputs": [], + "source": [ + "#S9 E\n", + "WAP in python which accepts string from the user and displays only those characters/elements which are present at an even index.\n", + "\n", + "Example: \n", + " Input: \"Python\"\n", + " Output: Pto" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "53764f91", + "metadata": {}, + "outputs": [], + "source": [ + "#S10 E\n", + "WAP in python to capitalize the first letter of the First Name and Surname where whole name is taken as input from the user.\n", + "\n", + "Example: Input: \"first last\" or \"FIRST LAST\" or \"first lAst\" i.e. Input can be in any case.\n", + " Output: \"First Last\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ecaf613f", + "metadata": {}, + "outputs": [], + "source": [ + "#S11 EM\n", + "Write a Python program that accepts a comma separated sequence of words as input and \n", + "prints the unique words in sorted form (alphanumerically).\n", + "\n", + "\tSample Words : red, white, black, red, green \n", + "\tExpected Result : black, green, red, red, white" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "352b362a", + "metadata": {}, + "outputs": [], + "source": [ + "#S12 MH\n", + "Write a Python program to count repeated characters in a string.\n", + "\n", + "\tSample string: 'thequickbrownfoxjumpsoverthelazydog'\n", + "\tExpected output :\n", + "\t\t\to 4\n", + "\t\t\te 3\n", + "\t\t\tu 2\n", + "\t\t\th 2\n", + "\t\t\tr 2\n", + "\t\t\tt 2" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "6863e28a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('t', 2), ('h', 2), ('e', 3), ('u', 2), ('r', 2), ('o', 4), ('o', 4), ('u', 2), ('o', 4), ('e', 3), ('r', 2), ('t', 2), ('h', 2), ('e', 3), ('o', 4)]\n", + "[('e', 3), ('h', 2), ('r', 2), ('t', 2), ('o', 4), ('u', 2)]\n" + ] + } + ], + "source": [ + "mystring = 'thequickbrownfoxjumpsoverthelazydog'\n", + "\n", + "res = []\n", + "\n", + "for s in mystring : \n", + " count = mystring.count(s)\n", + "# print(count)\n", + " if count > 1 : \n", + " res.append( (s, count) )\n", + "\n", + "print(res)\n", + "print( list( set(res) ) )\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3b1ae325", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "acb63598", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "a8e69e94", + "metadata": {}, + "source": [ + "### List Questions" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "087e7496", + "metadata": {}, + "outputs": [], + "source": [ + "#Li1 M\n", + "WAP to remove empty strings from the list of strings. Take list as input from the user.\n", + "\n", + "For example: Input: [\"My\", \"name\", \"\", \"is\", \"\", \"Alankrita\", \"\", \".\"]\n", + " Output: [\"My\", \"name\", \"is\", \"Alankrita\", \".\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c78eb9de", + "metadata": {}, + "outputs": [], + "source": [ + "## HINT : check the len" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "id": "e24bb93a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['My', 'name', '', 'is', '', 'Alankrita', '', '.']\n", + "['My', 'name', 'is', 'Alankrita', '.']\n" + ] + } + ], + "source": [ + "my_list= [\"My\", \"name\", \"\", \"is\", \"\", \"Alankrita\", \"\", \".\"]\n", + "print(str(my_list))\n", + "for i in my_list:\n", + " if \"\" in my_list:\n", + " my_list.remove( \"\")\n", + "print(my_list)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ef63e4e", + "metadata": {}, + "outputs": [], + "source": [ + "#Li2 H\n", + "WAP to make a list of all the characters starting from character 'A' to input charaacter from the user.\n", + "\n", + "For e.g. Input: 'H'\n", + " Output: [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "id": "bd6cdc38", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import string\n", + "string.ascii_uppercase" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "c1d8278f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mention the character : h\n", + "H\n", + "ABCDEFGH\n", + "['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']\n" + ] + } + ], + "source": [ + "import string\n", + "userChar = input( \"Mention the character : \" )\n", + "\n", + "if userChar.isalpha() : \n", + " userChar = userChar.upper().strip()\n", + " print(userChar)\n", + " \n", + " pos = string.ascii_uppercase.index(userChar)\n", + " print( string.ascii_uppercase[ : pos + 1] )\n", + " print( [ c for c in string.ascii_uppercase[ : pos + 1] ] )\n", + "# print( [ c.upper() for c in string.ascii_uppercase[ : pos + 1] ] )\n", + " \n", + " \n", + " \n", + "else : \n", + " print(\"Invalid Character\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d03be94a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f6f1edac", + "metadata": {}, + "outputs": [], + "source": [ + "#Li3 H\n", + "WAP to check if a specific employee e is present in a company or not. Employee names are saved in a list.\n", + "e is taken as input from the user.\n", + "\n", + "For example: empList = [\"Ashwin\", \"Rachit\", \"Sanjana\", \"David\", \"Komal\"]\n", + " Input1: \"Komal\"\n", + " Output1: \"Employee is present\"\n", + " \n", + " Input2: \"Nitish\"\n", + " Output2: \"Employee is not present\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a712bea9", + "metadata": {}, + "outputs": [], + "source": [ + "#Li4 M\n", + "Write a python program to find the maximum and minimum number in a list of 10 elements \n", + " (taken as input from the user) and also find the index position of the these numbers.\n", + " \n", + " For example: Input : [25, 2, 1, 86, 42, 32, 27, 12, 31, 10]\n", + "\t\tOutput: Max Number: 86, Index of Max Number: 3\n", + "\t\t\tMin Number: 1, Index of Min Number: 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "231efeba", + "metadata": {}, + "outputs": [], + "source": [ + "#Li5 M\n", + "Given two Python lists of same length. Iterate both lists simultaneously such that list1 \n", + " should display item in original order and list2 in reverse order.\n", + " \n", + " For example: Input = list1 = [10, 20, 30, 40]\n", + "\t\t\tlist2 = [100, 200, 300, 400]\n", + " Output: 10 400\n", + " 20 300\n", + " 30 200\n", + " 40 100" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "f9c60f87", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 400\n", + "20 300\n", + "30 200\n", + "40 100\n" + ] + } + ], + "source": [ + "list1 = [10, 20, 30, 40]\n", + "list2 = [100, 200, 300, 400]\n", + "list2 = list2[ : : -1]\n", + "\n", + "for i in range( len(list1) ) : \n", + " print( list1[i], list2[i] )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a0e72be4", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6a942a95", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2c3a2444", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1f09b084", + "metadata": {}, + "outputs": [], + "source": [ + "#Li6 M\n", + "WAP to concatenate two lists index-wise.\n", + " list1 = [\"M\", \"na\", \"i\", \"Ashu\"]\n", + " list2 = [\"y\", \"me\", \"s\", \"tosh\"]\n", + " Output: ['My', 'name', 'is', 'Ashutosh']" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "id": "deeab5e3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My\n", + "name\n", + "is\n", + "Ashutosh\n" + ] + } + ], + "source": [ + "list1 = [\"M\", \"na\", \"i\", \"Ashu\"]\n", + "list2 = [\"y\", \"me\", \"s\", \"tosh\"]\n", + "\n", + "for i in range( len(list1) ) : \n", + " print( list1[i] + list2[i] ) # .append()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a1b5483d", + "metadata": {}, + "outputs": [], + "source": [ + " #Li7 M\n", + "# WAP to remove/delete items from a list while iterating without creating a duplicate list.\n", + "# Take the elements to be deleted from the user in real-time.\n", + "# Input : \n", + "# # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n", + "# # Enter Number between 0 - 9 : 4\n", + "\n", + "# Output : \n", + "# # [0, 1, 2, 3, 5, 6, 7, 8, 9]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c33725ae", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "10d5de6c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "96702298", + "metadata": {}, + "outputs": [], + "source": [ + "#Li8 E\n", + "WAP to generate a Python list of all the prime numbers between n to m where n & m are taken as input from the user.\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "ac38f3fc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number is prime\n" + ] + } + ], + "source": [ + "number = 11\n", + "flag = True # This is Prime\n", + "\n", + "for each in range(2, number) : \n", + " if number % each == 0:\n", + " flag = False\n", + " break\n", + " else : \n", + " flag = True\n", + "\n", + "if flag : \n", + " print(\"Number is prime\")\n", + "\n", + "else : \n", + " print(\"Number is not prime\")" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "07bad668", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2 Number is prime\n", + "3 Number is prime\n", + "4 Number is not prime\n", + "5 Number is prime\n", + "6 Number is not prime\n", + "7 Number is prime\n", + "8 Number is not prime\n", + "9 Number is not prime\n", + "10 Number is not prime\n", + "11 Number is prime\n" + ] + } + ], + "source": [ + "\n", + "\n", + "number = 11\n", + "\n", + "for num in range(2, number + 1) : \n", + "\n", + " flag = True # This is Prime\n", + "\n", + " for each in range(2, num) : \n", + " if num % each == 0:\n", + " flag = False\n", + " break\n", + " else : \n", + " flag = True\n", + "\n", + " if flag : \n", + " print(num, \"Number is prime\")\n", + "\n", + " else : \n", + " print(num , \"Number is not prime\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7c34998b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2ae91e86", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c9d71f07", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9da0e504", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2a09259b", + "metadata": {}, + "outputs": [], + "source": [ + "#Li9 M\n", + "WAP to concatenate two lists in the following order:\n", + " list1 = [\"Hello \", \"World\"]\n", + " list2 = [\"Hi\", \"There\"]\n", + " Output: ['Hello Hi', 'Hello There', 'World Hi', 'World There']" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "2b8ae8f7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the name: Komal\n", + "27\n" + ] + } + ], + "source": [ + "# Li10 M\n", + "Given two lists having names of students and their corresponding marks.\n", + "names = [\"Ashutosh\", \"Ajay\", \"Alankrita\", \"Rachit\", \"Komal\", \"Anil\"]\n", + "marks = [23, 21, 26, 23, 27, 24]\n", + "Take name of a student as input from the user and output his/her marks.\n", + "\n", + "For e.g.:\n", + " Input1: \"Alankrita\"\n", + " Output1: 26\n", + " \n", + " Input2: \"Someone\"\n", + " Output2: \"Student not found\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9641b662", + "metadata": {}, + "outputs": [], + "source": [ + "#Li11 H\n", + "Extended question of #Li10\n", + "Add an option to change marks of any students in the same code of #Li10. Take student name and new marks from the user. \n", + "Print the modified list as output.\n", + "\n", + "For e.g.: Input: \"Ajay\"\n", + " new_mark: 25\n", + " Output: marks = [23, 25, 26, 23, 27, 24]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47a72de0", + "metadata": {}, + "outputs": [], + "source": [ + "#Li12 H\n", + "Extended question of #Li10\n", + "Give an option to enter the marks of a new student into the existing lists names and marks. Take new data as input from user.\n", + "Print the new names and marks list as output.\n", + "\n", + "For e.g.: Input: New_name = \"Nitish\"\n", + " new_Marks = 20\n", + " Output: names = [\"Ashutosh\", \"Ajay\", \"Alankrita\", \"Rachit\", \"Komal\", \"Anil\", \"Nitish\"]\n", + " marks = [23, 21, 26, 23, 27, 24, 20]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1563e790", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "886e40bf", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "2494ea58", + "metadata": {}, + "source": [ + "### Dictionary Questions" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8c4800f5", + "metadata": {}, + "outputs": [], + "source": [ + "#D1\n", + "WAP in Python to merge following dictionaries to create a new one:\n", + "\tdic1={1:10, 2:20}\n", + "\tdic2={3:30, 4:40}\n", + "\tdic3={5:50, 6:60}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fe0bb9cb", + "metadata": {}, + "outputs": [], + "source": [ + "#D2\n", + "WAP in python to generate and print a dictionary that contains a number (between 1 and n) \n", + "in the form {x : x*x} where n is the input from the user.\n", + "\n", + "For e.g. Input: 4\n", + " Output: {1:1, 2:4, 3:9, 4:16}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "931100ac", + "metadata": {}, + "outputs": [], + "source": [ + "#D3\n", + "WAP in python to find the number of vowels, consonants, digits, white space characters & \n", + "special characters in a string and save the result in the form of a dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ce8abd97", + "metadata": {}, + "outputs": [], + "source": [ + "#D4\n", + "WAP to reverse map the dictionary items. Take dictionary as input from the user.\n", + "\n", + "\tFor eg., Input: d = {'A': 65, 'B': 66, 'C': 67, 'D': 68}\n", + " Output: d = {65: 'A', 66: 'B', 67: 'C', 68: 'D'}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "838003f4", + "metadata": {}, + "outputs": [], + "source": [ + "#D5\n", + "WAP to save Username and Password of 10 employees in an organisation. \n", + "Take the Username and Password as input from the user one by one and save in the Dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f1e40f13", + "metadata": {}, + "outputs": [], + "source": [ + "#D6\n", + "Extended Question from #D5\n", + "Write an additional functionality to check if an employee is present in the organisation or not.\n", + "Basically \"Search\" Functionality based on their username\n", + "Take employee name as input from the user.\n", + "If the employee is present, print \"Present\" else print \"Not Present\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0888fa4d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "794c6101", + "metadata": {}, + "source": [ + "### Misc. Questions - i.e. you can use any data type which seems feasible for question" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c7657f9f", + "metadata": {}, + "outputs": [], + "source": [ + "#M1\n", + "WAP in python that accepts two integers (n) & (m) from user and \n", + "computes the value of 2n3 + 5m2 - 7n + 10" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e591afe3", + "metadata": {}, + "outputs": [], + "source": [ + "#M2\n", + "Write a python program to find the intersection of elements from two list \n", + "(find the common elements in two lists)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d90c6f7a", + "metadata": {}, + "outputs": [], + "source": [ + "#M3\n", + "WAP in Python to find the Max of n numbers all taken as input from the user." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3bf138a8", + "metadata": {}, + "outputs": [], + "source": [ + "#M4\n", + "WAP which takes a sequence of numbers from the user and check if all input numbers are unique." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31a341b5", + "metadata": {}, + "outputs": [], + "source": [ + "#M5\n", + "WAP to reverse a given integer number.\n", + "Example: Input: 105320\n", + " Output: 023501" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f16426d4", + "metadata": {}, + "outputs": [], + "source": [ + "#M6\n", + "WAP to take 10 integer inputs from the user and save them in a list. \n", + "The inputs have to be mix of even and odd numbers. \n", + "Now make one list to save all the even numbers from the input list. \n", + "Make another list for odd numbers too." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "192d42d9", + "metadata": {}, + "outputs": [], + "source": [ + "#M7\n", + "WAP to convert temperature in Fahrenheit to Celsius. Take the temperature from the user in float type." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "de4dbe73", + "metadata": {}, + "outputs": [], + "source": [ + "#M8\n", + "WAP to continuously take Names as input from the user. \n", + "Save the incoming names into a list as Full Name and save {First Name:Second Name} in a dictionary.\n", + "Take inputs till the user enters \"Stop\"\n", + "\n", + "For e.g.: Input: \"Shahrukh Khan\", \"Gauri Khan\",...................\"Stop\"\n", + " Output: list1 = [\"Shahrukh Khan\", \"Gauri Khan\",....................]\n", + " dict1 = {\"Shahrukh\":\"Khan\", \"Gauri\":\"Khan\", .....................}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "53e01c1a", + "metadata": {}, + "outputs": [], + "source": [ + "#M9\n", + "WAP to make a simple and compound interest calculator. Take all the necessary data as input from the user." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6b01fca0", + "metadata": {}, + "outputs": [], + "source": [ + "#M10\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ea02423f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eaffaf35", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4d5de745", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}