Created
December 10, 2015 15:20
-
-
Save tsu-nera/6e8405a8531c5d6933a7 to your computer and use it in GitHub Desktop.
SRM 675 Div2 250
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
| # -*- coding: utf-8 -*- | |
| import math,string,itertools,fractions,heapq,collections,re,array,bisect | |
| class LengthUnitCalculator: | |
| def calc(self, amount, fromUnit, toUnit): | |
| if fromUnit == toUnit: | |
| return amount | |
| if fromUnit == "in": | |
| if toUnit == "ft": | |
| return amount / 12 | |
| elif toUnit == "yd": | |
| return amount / (12 * 3) | |
| elif toUnit == "mi": | |
| return amount / (12 * 3 * 1760) | |
| if fromUnit == "ft": | |
| if toUnit == "in": | |
| return amount * 12 | |
| elif toUnit == "yd": | |
| return amount / 3 | |
| elif toUnit == "mi": | |
| return amount / (3 * 1760) | |
| if fromUnit == "yd": | |
| if toUnit == "in": | |
| return amount * 3 * 12 | |
| elif toUnit == "ft": | |
| return amount * 3 | |
| elif toUnit == "mi": | |
| return amount / 1760 | |
| if fromUnit == "mi": | |
| if toUnit == "in": | |
| return amount * 12 * 3 * 1760 | |
| elif toUnit == "ft": | |
| return amount * 3 * 1760 | |
| elif toUnit == "yd": | |
| return amount * 1760 | |
| return 0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment