Skip to content

Commit 002d43e

Browse files
authored
Merge pull request #4 from imadahmad97/adding_basic_calculator
Added basic calculator app
2 parents 0a8c839 + 6d83db4 commit 002d43e

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

Calculator/.DS_Store

6 KB
Binary file not shown.

Calculator/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Calulator
2+
3+
### A basic calculator app that takes two numbers as input, then performs *one of* addition, multiplication, subtraction, division.
4+
5+
### To run
6+
7+
You need to put the next command to run background:
8+
9+
For **Windows**:
10+
```
11+
pythonw .\main.py
12+
```
13+
14+
For **Linux**:
15+
```
16+
python3 main.py&
17+
```
18+
19+
or run:
20+
```
21+
python3 main.py
22+
```
23+

Calculator/main.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Basic calculator functions that take two numbers
2+
def add(a,b):
3+
return a + b
4+
5+
def subtract(a,b):
6+
return a - b
7+
8+
def multiply(a,b):
9+
return a * b
10+
11+
def divide(a,b):
12+
return a / b
13+
14+
15+
# Defining variables from user input
16+
# Note: input() returns a string, so we need to convert to int for numbers
17+
a = int(input('What is your first number? '))
18+
b = int(input('What is your second number? '))
19+
c = input('What operation would you like to perform (add, subtract, multiply or divide)? ')
20+
21+
# Calling the appropriate function based on user input
22+
# Returning the result as an f-string
23+
if c == 'add':
24+
print(f'result: {add(a,b)}')
25+
elif c == 'subtract':
26+
print(f'result: {subtract(a,b)}')
27+
elif c == 'multiply':
28+
print(f'result: {multiply(a,b)}')
29+
elif c == 'divide':
30+
print(f'result: {divide(a,b)}')

0 commit comments

Comments
 (0)