mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Adding cli_calculator on project and also updating readme
This commit is contained in:
parent
42f18a2d4a
commit
f5046cde5a
|
@ -31,7 +31,7 @@ So far, the following projects have been integrated to this repo:
|
||||||
|[Gmail Mailing Script](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/mailing) |[mayank-kapur](https://github.com/kapurm17) |
|
|[Gmail Mailing Script](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/mailing) |[mayank-kapur](https://github.com/kapurm17) |
|
||||||
|[Handwrting DNN recognizer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Handwriting_Recognizer) |[Chris]() |
|
|[Handwrting DNN recognizer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Handwriting_Recognizer) |[Chris]() |
|
||||||
|[HTML Table to List](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/HTML_Table_to_List) | [Nitish Srivastava](https://github.com/nitish-iiitd)|
|
|[HTML Table to List](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/HTML_Table_to_List) | [Nitish Srivastava](https://github.com/nitish-iiitd)|
|
||||||
|[Image circle formatter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Image-Circulator) |[Berk Gureken](https://github.com/bureken) |
|
|[Image circle formatter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Image-Circulator) |[Berk Gureken](https://github.com/bureken) |
|
||||||
|[Image To PDF](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/images2pdf)|[msaoudallah](https://github.com/msaoudallah)|
|
|[Image To PDF](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/images2pdf)|[msaoudallah](https://github.com/msaoudallah)|
|
||||||
|[Instadp Web Scrapper](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/InstadpShower)|[Psychiquest](https://github.com/psychiquest)|
|
|[Instadp Web Scrapper](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/InstadpShower)|[Psychiquest](https://github.com/psychiquest)|
|
||||||
|[Own IP locator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Location_Of_Own_IP_Adress)|[Chris]()|
|
|[Own IP locator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Location_Of_Own_IP_Adress)|[Chris]()|
|
||||||
|
@ -53,6 +53,7 @@ So far, the following projects have been integrated to this repo:
|
||||||
|[Youtube video downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Youtube_Video_Downloader)|[Christopher He](https://github.com/hecris)|
|
|[Youtube video downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Youtube_Video_Downloader)|[Christopher He](https://github.com/hecris)|
|
||||||
|[Zabbix API](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/zabbix_api)|[msg4sunny](https://github.com/msg4sunny)|
|
|[Zabbix API](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/zabbix_api)|[msg4sunny](https://github.com/msg4sunny)|
|
||||||
|[Zip password cracker](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/zip_password_cracker)|[umar abdullahi](https://github.com/umarbrowser)|
|
|[Zip password cracker](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/zip_password_cracker)|[umar abdullahi](https://github.com/umarbrowser)|
|
||||||
|
|[CLI Calculator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/cli_calculator)|[Willian GL](https://github.com/williangl) |
|
||||||
|
|
||||||
## How to use :
|
## How to use :
|
||||||
|
|
||||||
|
@ -63,14 +64,14 @@ Remember to star the repo if you love the scipts~ :wink:
|
||||||
|
|
||||||
## Contribuition Guidelines :
|
## Contribuition Guidelines :
|
||||||
- Make a **separate folder** for your script.
|
- Make a **separate folder** for your script.
|
||||||
- There shouldn't be any **spaces** between the names of the script. (Use underscore or dash Symbol)
|
- There shouldn't be any **spaces** between the names of the script. (Use underscore or dash Symbol)
|
||||||
- :x: Script One
|
- :x: Script One
|
||||||
- :heavy_check_mark: Script_One
|
- :heavy_check_mark: Script_One
|
||||||
- :heavy_check_mark: Script-One
|
- :heavy_check_mark: Script-One
|
||||||
|
|
||||||
- The Folder should contain the followings -
|
- The Folder should contain the followings -
|
||||||
- Main Python Script,
|
- Main Python Script,
|
||||||
- Supporting files for the Script (If any)
|
- Supporting files for the Script (If any)
|
||||||
- A separate `README.md` File with proper documentation.
|
- A separate `README.md` File with proper documentation.
|
||||||
|
|
||||||
- Feel Free to add your script in the [project's list](https://github.com/hastagAB/Awesome-Python-Scripts#what-do-we-have) above.
|
- Feel Free to add your script in the [project's list](https://github.com/hastagAB/Awesome-Python-Scripts#what-do-we-have) above.
|
||||||
|
|
11
cli_calculator/README.md
Normal file
11
cli_calculator/README.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# calc_argparser
|
||||||
|
Calculadora via CLI
|
||||||
|
|
||||||
|
# Instructions
|
||||||
|
To run CLI_Calculator execute:
|
||||||
|
|
||||||
|
- `python args.py -h` - For help
|
||||||
|
- `python args.py --sum x y` - To sum two numbers
|
||||||
|
- `python args.py --sub x y` - To substraction two numbers
|
||||||
|
- `python args.py --mult x y` - To multiplication two numbers
|
||||||
|
- `python args.py --div x y` - To divide two numbers
|
3
cli_calculator/calc/__init__.py
Normal file
3
cli_calculator/calc/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from .calc import sub, mult, div, soma
|
||||||
|
|
||||||
|
__all__ = ['sub', 'mult', 'div', 'soma']
|
29
cli_calculator/calc/args.py
Normal file
29
cli_calculator/calc/args.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
"""Calculadora utilizando ArgumentParser."""
|
||||||
|
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
from calc import soma, sub, mult, div
|
||||||
|
|
||||||
|
|
||||||
|
parser = ArgumentParser(description='Calculadora')
|
||||||
|
|
||||||
|
parser.add_argument('--sum', help='Operação de soma', action='store_true')
|
||||||
|
parser.add_argument('--sub', help='Operação de subtração', action='store_true')
|
||||||
|
parser.add_argument('--mult', help='Operação de multiplicação', action='store_true')
|
||||||
|
parser.add_argument('--div', help='Operação de divisão', action='store_true')
|
||||||
|
parser.add_argument('x', type=int, help='Primeiro valor')
|
||||||
|
parser.add_argument('y', type=int, help='Segundo valor')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.sum:
|
||||||
|
print(f'{soma(args.x, args.y)}')
|
||||||
|
|
||||||
|
if args.sub:
|
||||||
|
print(f'{sub(args.x, args.y)}')
|
||||||
|
|
||||||
|
if args.mult:
|
||||||
|
print(f'{mult(args.x, args.y)}')
|
||||||
|
|
||||||
|
if args.div:
|
||||||
|
print(f'{div(args.x, args.y)}')
|
22
cli_calculator/calc/calc.py
Normal file
22
cli_calculator/calc/calc.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
def soma(x :int, y: int) -> int:
|
||||||
|
"""Função de soma."""
|
||||||
|
return x + y
|
||||||
|
|
||||||
|
|
||||||
|
def sub(x :int, y: int) -> int:
|
||||||
|
"""Função de subtração."""
|
||||||
|
return x - y
|
||||||
|
|
||||||
|
def mult(x :int, y: int) -> int:
|
||||||
|
"""Função de multiplicação."""
|
||||||
|
return x * y
|
||||||
|
|
||||||
|
|
||||||
|
def div(x :int, y: int) -> int:
|
||||||
|
"""Função de divisão."""
|
||||||
|
try:
|
||||||
|
return x / y
|
||||||
|
|
||||||
|
except ZeroDivisionError:
|
||||||
|
return 'Divisao por zero mal sucedida!!'
|
28
cli_calculator/tests/test_calc.py
Normal file
28
cli_calculator/tests/test_calc.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from calc import soma, sub, mult, div
|
||||||
|
|
||||||
|
|
||||||
|
class testCalc(TestCase):
|
||||||
|
def test_should_return_two_values_sum(self):
|
||||||
|
esperado = 1 + 2
|
||||||
|
self.assertEqual(esperado, soma(1,2))
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_return_two_values_sub(self):
|
||||||
|
esperado = 1 - 2
|
||||||
|
self.assertEqual(esperado, sub(1,2))
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_return_two_values_mult(self):
|
||||||
|
esperado = 1 * 2
|
||||||
|
self.assertEqual(esperado, mult(1,2))
|
||||||
|
|
||||||
|
def test_should_return_two_values_div(self):
|
||||||
|
esperado = 1 / 2
|
||||||
|
self.assertEqual(esperado, div(1,2))
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_return_exceptio_on_division_by_zero(self):
|
||||||
|
esperado = 'Divisao por zero mal sucedida!!'
|
||||||
|
self.assertEqual(esperado, div(1,0))
|
Loading…
Reference in New Issue
Block a user