diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..fa77bd3 Binary files /dev/null and b/.DS_Store differ diff --git a/Calculator/.DS_Store b/Calculator/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/Calculator/.DS_Store differ diff --git a/Calculator/README.md b/Calculator/README.md new file mode 100644 index 0000000..b713fb3 --- /dev/null +++ b/Calculator/README.md @@ -0,0 +1,23 @@ +# Calulator + +### A basic calculator app that takes two numbers as input, then performs *one of* addition, multiplication, subtraction, division. + +### To run + +You need to put the next command to run background: + +For **Windows**: +``` +pythonw .\main.py +``` + +For **Linux**: +``` +python3 main.py& +``` + +or run: +``` +python3 main.py +``` + diff --git a/Calculator/main.py b/Calculator/main.py new file mode 100644 index 0000000..a7d8919 --- /dev/null +++ b/Calculator/main.py @@ -0,0 +1,30 @@ +# Basic calculator functions that take two numbers +def add(a,b): + return a + b + +def subtract(a,b): + return a - b + +def multiply(a,b): + return a * b + +def divide(a,b): + return a / b + + +# Defining variables from user input +# Note: input() returns a string, so we need to convert to int for numbers +a = int(input('What is your first number? ')) +b = int(input('What is your second number? ')) +c = input('What operation would you like to perform (add, subtract, multiply or divide)? ') + +# Calling the appropriate function based on user input +# Returning the result as an f-string +if c == 'add': + print(f'result: {add(a,b)}') +elif c == 'subtract': + print(f'result: {subtract(a,b)}') +elif c == 'multiply': + print(f'result: {multiply(a,b)}') +elif c == 'divide': + print(f'result: {divide(a,b)}')