1
+ {
2
+ "nbformat" : 4 ,
3
+ "nbformat_minor" : 0 ,
4
+ "metadata" : {
5
+ "colab" : {
6
+ "name" : " A_Simple_Calculator_Application.ipynb" ,
7
+ "version" : " 0.3.2" ,
8
+ "provenance" : []
9
+ },
10
+ "kernelspec" : {
11
+ "name" : " python3" ,
12
+ "display_name" : " Python 3"
13
+ }
14
+ },
15
+ "cells" : [
16
+ {
17
+ "cell_type" : " markdown" ,
18
+ "metadata" : {
19
+ "id" : " U3nxqxtH6UQt" ,
20
+ "colab_type" : " text"
21
+ },
22
+ "source" : [
23
+ " ## Python Program To Create A Simple Calculator Application\n " ,
24
+ " \n " ,
25
+ " ---\n " ,
26
+ " \n " ,
27
+ " \n " ,
28
+ " In this example, you will learn to create a simple calculator that can add, subtract, multiply or divide depending upon the input from the user."
29
+ ]
30
+ },
31
+ {
32
+ "cell_type" : " code" ,
33
+ "metadata" : {
34
+ "id" : " N0xGRW7Q5xsN" ,
35
+ "colab_type" : " code" ,
36
+ "colab" : {
37
+ "base_uri" : " https://localhost:8080/" ,
38
+ "height" : 170
39
+ },
40
+ "outputId" : " 0e4fe91c-f0ce-44c0-df75-0a261b9dfd48"
41
+ },
42
+ "source" : [
43
+ " # Program make a simple calculator that can add, subtract, multiply and divide using functions\n " ,
44
+ " \n " ,
45
+ " # This function adds two numbers \n " ,
46
+ " def add(x, y):\n " ,
47
+ " return x + y\n " ,
48
+ " \n " ,
49
+ " # This function subtracts two numbers \n " ,
50
+ " def subtract(x, y):\n " ,
51
+ " return x - y\n " ,
52
+ " \n " ,
53
+ " # This function multiplies two numbers\n " ,
54
+ " def multiply(x, y):\n " ,
55
+ " return x * y\n " ,
56
+ " \n " ,
57
+ " # This function divides two numbers\n " ,
58
+ " def divide(x, y):\n " ,
59
+ " return x / y\n " ,
60
+ " \n " ,
61
+ " print(\" Select operation.\" )\n " ,
62
+ " print(\" 1.Add\" )\n " ,
63
+ " print(\" 2.Subtract\" )\n " ,
64
+ " print(\" 3.Multiply\" )\n " ,
65
+ " print(\" 4.Divide\" )\n " ,
66
+ " \n " ,
67
+ " # Take input from the user \n " ,
68
+ " choice = input(\" Enter choice(1/2/3/4):\" )\n " ,
69
+ " \n " ,
70
+ " num1 = int(input(\" Enter first number: \" ))\n " ,
71
+ " num2 = int(input(\" Enter second number: \" ))\n " ,
72
+ " \n " ,
73
+ " if choice == '1':\n " ,
74
+ " print(num1,\" +\" ,num2,\" =\" , add(num1,num2))\n " ,
75
+ " \n " ,
76
+ " elif choice == '2':\n " ,
77
+ " print(num1,\" -\" ,num2,\" =\" , subtract(num1,num2))\n " ,
78
+ " \n " ,
79
+ " elif choice == '3':\n " ,
80
+ " print(num1,\" *\" ,num2,\" =\" , multiply(num1,num2))\n " ,
81
+ " \n " ,
82
+ " elif choice == '4':\n " ,
83
+ " print(num1,\" /\" ,num2,\" =\" , divide(num1,num2))\n " ,
84
+ " else:\n " ,
85
+ " print(\" Invalid input\" )"
86
+ ],
87
+ "execution_count" : 1 ,
88
+ "outputs" : [
89
+ {
90
+ "output_type" : " stream" ,
91
+ "text" : [
92
+ " Select operation.\n " ,
93
+ " 1.Add\n " ,
94
+ " 2.Subtract\n " ,
95
+ " 3.Multiply\n " ,
96
+ " 4.Divide\n " ,
97
+ " Enter choice(1/2/3/4):1\n " ,
98
+ " Enter first number: 4\n " ,
99
+ " Enter second number: 5\n " ,
100
+ " 4 + 5 = 9\n "
101
+ ],
102
+ "name" : " stdout"
103
+ }
104
+ ]
105
+ }
106
+ ]
107
+ }
0 commit comments