|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Calculator<br>\n", |
| 8 | + "<br>\n", |
| 9 | + "Write a program that performs the tasks of a simple calculator. The program should first take an integer as input and then based on that integer perform the task as given below.<br>\n", |
| 10 | + "<br>\n", |
| 11 | + "1. If the input is 1, 2 integers are taken from the user and their sum is printed.<br>\n", |
| 12 | + "2. If the input is 2, 2 integers are taken from the user and their difference(1st number - 2nd number) is printed.<br>\n", |
| 13 | + "3. If the input is 3, 2 integers are taken from the user and their product is printed.<br>\n", |
| 14 | + "4. If the input is 4, 2 integers are taken from the user and the quotient obtained (on dividing 1st number by 2nd number) is printed.<br>\n", |
| 15 | + "5. If the input is 5, 2 integers are taken from the user and their remainder(1st number mod 2nd number) is printed.<br>\n", |
| 16 | + "6. If the input is 6, the program exits.<br>\n", |
| 17 | + "7. For any other input, print "Invalid Operation".<br>\n", |
| 18 | + "Note: Each answer in next line.<br>\n", |
| 19 | + "<br>\n", |
| 20 | + "Input format:<br>\n", |
| 21 | + "Take integers as input, in accordance to the description of the question. <br>\n", |
| 22 | + "<br>\n", |
| 23 | + "Constraints:<br>\n", |
| 24 | + "Time Limit: 1 second<br>\n", |
| 25 | + "<br>\n", |
| 26 | + "Output format:<br>\n", |
| 27 | + "The output lines must be as prescribed in the description of the question.<br>\n", |
| 28 | + "<br>\n", |
| 29 | + "Sample Input:<br>\n", |
| 30 | + "3<br>\n", |
| 31 | + "1<br>\n", |
| 32 | + "2<br>\n", |
| 33 | + "4<br>\n", |
| 34 | + "4<br>\n", |
| 35 | + "2<br>\n", |
| 36 | + "1<br>\n", |
| 37 | + "3<br>\n", |
| 38 | + "2<br>\n", |
| 39 | + "7<br>\n", |
| 40 | + "6<br>\n", |
| 41 | + "Sample Output:<br>\n", |
| 42 | + "2<br>\n", |
| 43 | + "2<br>\n", |
| 44 | + "5<br>\n", |
| 45 | + "Invalid Operation" |
| 46 | + ] |
| 47 | + }, |
| 48 | + { |
| 49 | + "cell_type": "code", |
| 50 | + "execution_count": null, |
| 51 | + "metadata": {}, |
| 52 | + "outputs": [], |
| 53 | + "source": [ |
| 54 | + "while True:\n", |
| 55 | + " n = int(input())\n", |
| 56 | + " if n == 1:\n", |
| 57 | + " n1 = int(input())\n", |
| 58 | + " n2 = int(input())\n", |
| 59 | + " print(int(n1+n2))\n", |
| 60 | + " elif n == 2:\n", |
| 61 | + " n1 = int(input())\n", |
| 62 | + " n2 = int(input())\n", |
| 63 | + " print(int(n1-n2))\n", |
| 64 | + " elif n == 3:\n", |
| 65 | + " n1 = int(input())\n", |
| 66 | + " n2 = int(input())\n", |
| 67 | + " print(int(n1*n2))\n", |
| 68 | + " elif n == 4:\n", |
| 69 | + " n1 = int(input())\n", |
| 70 | + " n2 = int(input())\n", |
| 71 | + " print(int(n1/n2))\n", |
| 72 | + " elif n == 5:\n", |
| 73 | + " n1 = int(input())\n", |
| 74 | + " n2 = int(input())\n", |
| 75 | + " print(int(n1//n2))\n", |
| 76 | + " elif n == 6:\n", |
| 77 | + " exit()\n", |
| 78 | + " else:\n", |
| 79 | + " print(\"Invalid Operation\")" |
| 80 | + ] |
| 81 | + } |
| 82 | + ], |
| 83 | + "metadata": { |
| 84 | + "kernelspec": { |
| 85 | + "display_name": "Python 3", |
| 86 | + "language": "python", |
| 87 | + "name": "python3" |
| 88 | + }, |
| 89 | + "language_info": { |
| 90 | + "codemirror_mode": { |
| 91 | + "name": "ipython", |
| 92 | + "version": 3 |
| 93 | + }, |
| 94 | + "file_extension": ".py", |
| 95 | + "mimetype": "text/x-python", |
| 96 | + "name": "python", |
| 97 | + "nbconvert_exporter": "python", |
| 98 | + "pygments_lexer": "ipython3", |
| 99 | + "version": "3.8.6" |
| 100 | + } |
| 101 | + }, |
| 102 | + "nbformat": 4, |
| 103 | + "nbformat_minor": 4 |
| 104 | +} |
0 commit comments