Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inforkgodara/python-calculator
It is a basic python calculator.
https://github.com/inforkgodara/python-calculator
calculator inforkgodara multiplication python python-calculator subtraction
Last synced: 16 days ago
JSON representation
It is a basic python calculator.
- Host: GitHub
- URL: https://github.com/inforkgodara/python-calculator
- Owner: inforkgodara
- Created: 2020-07-04T18:38:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-16T10:45:04.000Z (over 4 years ago)
- Last Synced: 2024-10-30T08:21:09.712Z (2 months ago)
- Topics: calculator, inforkgodara, multiplication, python, python-calculator, subtraction
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Python Calculator
It is a basic python calculator which can perform basic arithmetic operations like addition, subtraction, multiplication. Python 3.8 is used for the implementation.
## Approach
* User enter number (single digit or n character) to perform a specific operation like 1, 2, 3, 4 and n (n is to cancel calculation operation) are valid.
* Taking two numbers as inputs and used branching if elif else to perform a particular section.
* Using functions add(), subtract(), multiply() to perform specific task after given data to the system.## Code
```
# Program make a basic calculator
# Author @inforkgodara# Function adds two numbers
def add(first_number, second_number):
return first_number + second_number# Function subtracts two numbers
def subtract(first_number, second_number):
return first_number - second_number# Function multiplies two numbers
def multiply(first_number, second_number):
return first_number * second_number# Function divides two numbers
def divide(first_number, second_number):
return first_number / second_numberprint('Select options.')
print('1. Add')
print('2. Subtract')
print('3. Multiply')
print('4. Divide')while True:
# Take input from the console
choice = input('Enter choice(1/2/3/4 or n to cancel): ')
# Check if choice is one of the five options
if choice in ('1', '2', '3', '4'):
first_number = float(input('Enter first number: '))
second_number = float(input('Enter second number: '))if choice == '1':
print(first_number, '+', second_number, '=', add(first_number, second_number))elif choice == '2':
print(first_number, '-', second_number, '=', subtract(first_number, second_number))elif choice == '3':
print(first_number, '*', second_number, '=', multiply(first_number, second_number))elif choice == '4':
print(first_number, '/', second_number, '=', divide(first_number, second_number))
elif choice == 'n':
print('Your are successfully logged out!')
break
else:
print('Please enter correct input among these 1/2/3/4/n')```