Last active
December 12, 2018 10:58
-
-
Save amitkot/f14971be9356b91f1a42060a177f74d7 to your computer and use it in GitHub Desktop.
Fun with decimals, useful for big numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import Decimal | |
import re | |
def ddiff(str): | |
numbers = re.findall(r'\d+', str) | |
print(f'0: {numbers[0]}') | |
print(f'1: {numbers[1]}') | |
print(f'diff: {Decimal(numbers[0]) - Decimal(numbers[1])}') | |
def dsum(): | |
items = [] | |
while True: | |
num = input('Enter number: ') | |
if not num: break | |
items.append(Decimal(num)) | |
print('---') | |
print(f'Numbers: {items}') | |
print(f'Sum: {sum(items)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment