From 84cfa1c9d41205babf16d98d073a866e9194f5f3 Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Thu, 23 Jul 2020 15:37:54 -0700 Subject: [PATCH 1/5] add Rankine scale black formatting --- conversions/temperature_conversions.py | 180 +++++++++++++++++++++++-- 1 file changed, 169 insertions(+), 11 deletions(-) diff --git a/conversions/temperature_conversions.py b/conversions/temperature_conversions.py index 6b99d7688e44..a9a10780a850 100644 --- a/conversions/temperature_conversions.py +++ b/conversions/temperature_conversions.py @@ -23,6 +23,42 @@ def celsius_to_fahrenheit(celsius: float) -> float: return round((float(celsius) * 9 / 5) + 32, 2) +def celsius_to_kelvin(celsius: float) -> float: + """ + Convert a given value from Celsius to Kelvin and round it to 2 decimal places. + + >>> celsius_to_kelvin(0) + 273.15 + >>> celsius_to_kelvin(20.0) + 293.15 + >>> celsius_to_kelvin("40") + 313.15 + >>> celsius_to_kelvin("celsius") + Traceback (most recent call last): + ... + ValueError: could not convert string to float: 'celsius' + """ + return round(float(celsius) + 273.15, 2) + + +def celsius_to_rankine(celsius: float) -> float: + """ + Convert a given value from Celsius to Rankine and round it to 2 decimal places. + + >>> celsius_to_rankine(0) + 491.67 + >>> celsius_to_rankine(20.0) + 527.67 + >>> celsius_to_rankine("40") + 563.67 + >>> celsius_to_rankine("celsius") + Traceback (most recent call last): + ... + ValueError: could not convert string to float: 'celsius' + """ + return round((float(celsius) * 9 / 5) + 491.67, 2) + + def fahrenheit_to_celsius(fahrenheit: float) -> float: """ Convert a given value from Fahrenheit to Celsius and round it to 2 decimal places. @@ -47,22 +83,52 @@ def fahrenheit_to_celsius(fahrenheit: float) -> float: return round((float(fahrenheit) - 32) * 5 / 9, 2) -def celsius_to_kelvin(celsius: float) -> float: +def fahrenheit_to_kelvin(fahrenheit: float) -> float: """ - Convert a given value from Celsius to Kelvin and round it to 2 decimal places. + Convert a given value from Fahrenheit to Kelvin and round it to 2 decimal places. - >>> celsius_to_kelvin(0) - 273.15 - >>> celsius_to_kelvin(20.0) - 293.15 - >>> celsius_to_kelvin("40") - 313.15 - >>> celsius_to_kelvin("celsius") + >>> fahrenheit_to_kelvin(0) + 255.37 + >>> fahrenheit_to_kelvin(20.0) + 266.48 + >>> fahrenheit_to_kelvin(40.0) + 277.59 + >>> fahrenheit_to_kelvin(60) + 288.71 + >>> fahrenheit_to_kelvin(80) + 299.82 + >>> fahrenheit_to_kelvin("100") + 310.93 + >>> fahrenheit_to_kelvin("fahrenheit") Traceback (most recent call last): ... - ValueError: could not convert string to float: 'celsius' + ValueError: could not convert string to float: 'fahrenheit' """ - return round(float(celsius) + 273.15, 2) + return round(((float(fahrenheit) - 32) * 5 / 9) + 273.15, 2) + + +def fahrenheit_to_rankine(fahrenheit: float) -> float: + """ + Convert a given value from Fahrenheit to Rankine and round it to 2 decimal places. + + >>> fahrenheit_to_rankine(0) + 459.67 + >>> fahrenheit_to_rankine(20.0) + 479.67 + >>> fahrenheit_to_rankine(40.0) + 499.67 + >>> fahrenheit_to_rankine(60) + 519.67 + >>> fahrenheit_to_rankine(80) + 539.67 + >>> fahrenheit_to_rankine("100") + 559.67 + >>> fahrenheit_to_rankine("fahrenheit") + Traceback (most recent call last): + ... + ValueError: could not convert string to float: 'fahrenheit' + """ + return round(float(fahrenheit) + 459.67, 2) def kelvin_to_celsius(kelvin: float) -> float: @@ -83,6 +149,98 @@ def kelvin_to_celsius(kelvin: float) -> float: return round(float(kelvin) - 273.15, 2) +def kelvin_to_fahrenheit(kelvin: float) -> float: + """ + Convert a given value from Kelvin to Fahrenheit and round it to 2 decimal places. + + >>> kelvin_to_fahrenheit(273.15) + 32.0 + >>> kelvin_to_fahrenheit(300) + 80.33 + >>> kelvin_to_fahrenheit("315.5") + 108.23 + >>> kelvin_to_fahrenheit("kelvin") + Traceback (most recent call last): + ... + ValueError: could not convert string to float: 'kelvin' + """ + return round(((float(kelvin) - 273.15) * 9 / 5) + 32, 2) + + +def kelvin_to_rankine(kelvin: float) -> float: + """ + Convert a given value from Kelvin to Rankine and round it to 2 decimal places. + + >>> kelvin_to_rankine(0) + 0.0 + >>> kelvin_to_rankine(20.0) + 36.0 + >>> kelvin_to_rankine("40") + 72.0 + >>> kelvin_to_rankine("kelvin") + Traceback (most recent call last): + ... + ValueError: could not convert string to float: 'kelvin' + """ + return round((float(kelvin) * 9 / 5), 2) + + +def rankine_to_celsius(rankine: float) -> float: + """ + Convert a given value from Rankine to Celsius and round it to 2 decimal places. + + >>> rankine_to_celsius(273.15) + -121.4 + >>> rankine_to_celsius(300) + -106.48 + >>> rankine_to_celsius("315.5") + -97.87 + >>> rankine_to_celsius("rankine") + Traceback (most recent call last): + ... + ValueError: could not convert string to float: 'rankine' + """ + return round((float(rankine) - 491.67) * 5 / 9, 2) + + +def rankine_to_fahrenheit(rankine: float) -> float: + """ + Convert a given value from Rankine to Fahrenheit and round it to 2 decimal places. + + >>> rankine_to_fahrenheit(273.15) + -186.52 + >>> rankine_to_fahrenheit(300) + -159.67 + >>> rankine_to_fahrenheit("315.5") + -144.17 + >>> rankine_to_fahrenheit("rankine") + Traceback (most recent call last): + ... + ValueError: could not convert string to float: 'rankine' + """ + return round(float(rankine) - 459.67, 2) + + +def rankine_to_kelvin(rankine: float) -> float: + """ + Convert a given value from Rankine to Kelvin and round it to 2 decimal places. + + >>> rankine_to_kelvin(0) + 0.0 + >>> rankine_to_kelvin(20.0) + 11.11 + >>> rankine_to_kelvin("40") + 22.22 + >>> rankine_to_kelvin("rankine") + Traceback (most recent call last): + ... + ValueError: could not convert string to float: 'rankine' + """ + return round((float(rankine) * 5 / 9), 2) + + if __name__ == "__main__": + import doctest + doctest.testmod() From 55e47893837502f4c477800314201bac732a258e Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Fri, 24 Jul 2020 11:51:48 -0700 Subject: [PATCH 2/5] add Wikipedia links --- conversions/temperature_conversions.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/conversions/temperature_conversions.py b/conversions/temperature_conversions.py index a9a10780a850..05bc87de5fdb 100644 --- a/conversions/temperature_conversions.py +++ b/conversions/temperature_conversions.py @@ -4,6 +4,8 @@ def celsius_to_fahrenheit(celsius: float) -> float: """ Convert a given value from Celsius to Fahrenheit and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Celsius + Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit >>> celsius_to_fahrenheit(-40.0) -40.0 @@ -26,6 +28,8 @@ def celsius_to_fahrenheit(celsius: float) -> float: def celsius_to_kelvin(celsius: float) -> float: """ Convert a given value from Celsius to Kelvin and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Celsius + Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin >>> celsius_to_kelvin(0) 273.15 @@ -44,6 +48,8 @@ def celsius_to_kelvin(celsius: float) -> float: def celsius_to_rankine(celsius: float) -> float: """ Convert a given value from Celsius to Rankine and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Celsius + Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale >>> celsius_to_rankine(0) 491.67 @@ -62,6 +68,8 @@ def celsius_to_rankine(celsius: float) -> float: def fahrenheit_to_celsius(fahrenheit: float) -> float: """ Convert a given value from Fahrenheit to Celsius and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit + Wikipedia reference: https://en.wikipedia.org/wiki/Celsius >>> fahrenheit_to_celsius(0) -17.78 @@ -86,6 +94,8 @@ def fahrenheit_to_celsius(fahrenheit: float) -> float: def fahrenheit_to_kelvin(fahrenheit: float) -> float: """ Convert a given value from Fahrenheit to Kelvin and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit + Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin >>> fahrenheit_to_kelvin(0) 255.37 @@ -110,6 +120,8 @@ def fahrenheit_to_kelvin(fahrenheit: float) -> float: def fahrenheit_to_rankine(fahrenheit: float) -> float: """ Convert a given value from Fahrenheit to Rankine and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit + Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale >>> fahrenheit_to_rankine(0) 459.67 @@ -134,6 +146,8 @@ def fahrenheit_to_rankine(fahrenheit: float) -> float: def kelvin_to_celsius(kelvin: float) -> float: """ Convert a given value from Kelvin to Celsius and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin + Wikipedia reference: https://en.wikipedia.org/wiki/Celsius >>> kelvin_to_celsius(273.15) 0.0 @@ -152,6 +166,8 @@ def kelvin_to_celsius(kelvin: float) -> float: def kelvin_to_fahrenheit(kelvin: float) -> float: """ Convert a given value from Kelvin to Fahrenheit and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin + Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit >>> kelvin_to_fahrenheit(273.15) 32.0 @@ -170,6 +186,8 @@ def kelvin_to_fahrenheit(kelvin: float) -> float: def kelvin_to_rankine(kelvin: float) -> float: """ Convert a given value from Kelvin to Rankine and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin + Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale >>> kelvin_to_rankine(0) 0.0 @@ -188,6 +206,8 @@ def kelvin_to_rankine(kelvin: float) -> float: def rankine_to_celsius(rankine: float) -> float: """ Convert a given value from Rankine to Celsius and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale + Wikipedia reference: https://en.wikipedia.org/wiki/Celsius >>> rankine_to_celsius(273.15) -121.4 @@ -206,6 +226,8 @@ def rankine_to_celsius(rankine: float) -> float: def rankine_to_fahrenheit(rankine: float) -> float: """ Convert a given value from Rankine to Fahrenheit and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale + Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit >>> rankine_to_fahrenheit(273.15) -186.52 @@ -224,6 +246,8 @@ def rankine_to_fahrenheit(rankine: float) -> float: def rankine_to_kelvin(rankine: float) -> float: """ Convert a given value from Rankine to Kelvin and round it to 2 decimal places. + Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale + Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin >>> rankine_to_kelvin(0) 0.0 From 2ab6a7e35653b6457bf38f8a69ffb46815dd1256 Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Fri, 24 Jul 2020 12:57:13 -0700 Subject: [PATCH 3/5] add optional rounding, default to 2 digits --- conversions/temperature_conversions.py | 48 +++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/conversions/temperature_conversions.py b/conversions/temperature_conversions.py index 05bc87de5fdb..abc113eacdba 100644 --- a/conversions/temperature_conversions.py +++ b/conversions/temperature_conversions.py @@ -1,7 +1,7 @@ """ Convert between different units of temperature """ -def celsius_to_fahrenheit(celsius: float) -> float: +def celsius_to_fahrenheit(celsius: float, digits: int = 2) -> float: """ Convert a given value from Celsius to Fahrenheit and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Celsius @@ -22,10 +22,10 @@ def celsius_to_fahrenheit(celsius: float) -> float: ... ValueError: could not convert string to float: 'celsius' """ - return round((float(celsius) * 9 / 5) + 32, 2) + return round((float(celsius) * 9 / 5) + 32, digits) -def celsius_to_kelvin(celsius: float) -> float: +def celsius_to_kelvin(celsius: float, digits: int = 2) -> float: """ Convert a given value from Celsius to Kelvin and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Celsius @@ -42,10 +42,10 @@ def celsius_to_kelvin(celsius: float) -> float: ... ValueError: could not convert string to float: 'celsius' """ - return round(float(celsius) + 273.15, 2) + return round(float(celsius) + 273.15, digits) -def celsius_to_rankine(celsius: float) -> float: +def celsius_to_rankine(celsius: float, digits: int = 2) -> float: """ Convert a given value from Celsius to Rankine and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Celsius @@ -62,10 +62,10 @@ def celsius_to_rankine(celsius: float) -> float: ... ValueError: could not convert string to float: 'celsius' """ - return round((float(celsius) * 9 / 5) + 491.67, 2) + return round((float(celsius) * 9 / 5) + 491.67, digits) -def fahrenheit_to_celsius(fahrenheit: float) -> float: +def fahrenheit_to_celsius(fahrenheit: float, digits: int = 2) -> float: """ Convert a given value from Fahrenheit to Celsius and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit @@ -88,10 +88,10 @@ def fahrenheit_to_celsius(fahrenheit: float) -> float: ... ValueError: could not convert string to float: 'fahrenheit' """ - return round((float(fahrenheit) - 32) * 5 / 9, 2) + return round((float(fahrenheit) - 32) * 5 / 9, digits) -def fahrenheit_to_kelvin(fahrenheit: float) -> float: +def fahrenheit_to_kelvin(fahrenheit: float, digits: int = 2) -> float: """ Convert a given value from Fahrenheit to Kelvin and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit @@ -114,10 +114,10 @@ def fahrenheit_to_kelvin(fahrenheit: float) -> float: ... ValueError: could not convert string to float: 'fahrenheit' """ - return round(((float(fahrenheit) - 32) * 5 / 9) + 273.15, 2) + return round(((float(fahrenheit) - 32) * 5 / 9) + 273.15, digits) -def fahrenheit_to_rankine(fahrenheit: float) -> float: +def fahrenheit_to_rankine(fahrenheit: float, digits: int = 2) -> float: """ Convert a given value from Fahrenheit to Rankine and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit @@ -140,10 +140,10 @@ def fahrenheit_to_rankine(fahrenheit: float) -> float: ... ValueError: could not convert string to float: 'fahrenheit' """ - return round(float(fahrenheit) + 459.67, 2) + return round(float(fahrenheit) + 459.67, digits) -def kelvin_to_celsius(kelvin: float) -> float: +def kelvin_to_celsius(kelvin: float, digits: int = 2) -> float: """ Convert a given value from Kelvin to Celsius and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin @@ -160,10 +160,10 @@ def kelvin_to_celsius(kelvin: float) -> float: ... ValueError: could not convert string to float: 'kelvin' """ - return round(float(kelvin) - 273.15, 2) + return round(float(kelvin) - 273.15, digits) -def kelvin_to_fahrenheit(kelvin: float) -> float: +def kelvin_to_fahrenheit(kelvin: float, digits: int = 2) -> float: """ Convert a given value from Kelvin to Fahrenheit and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin @@ -180,10 +180,10 @@ def kelvin_to_fahrenheit(kelvin: float) -> float: ... ValueError: could not convert string to float: 'kelvin' """ - return round(((float(kelvin) - 273.15) * 9 / 5) + 32, 2) + return round(((float(kelvin) - 273.15) * 9 / 5) + 32, digits) -def kelvin_to_rankine(kelvin: float) -> float: +def kelvin_to_rankine(kelvin: float, digits: int = 2) -> float: """ Convert a given value from Kelvin to Rankine and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin @@ -200,10 +200,10 @@ def kelvin_to_rankine(kelvin: float) -> float: ... ValueError: could not convert string to float: 'kelvin' """ - return round((float(kelvin) * 9 / 5), 2) + return round((float(kelvin) * 9 / 5), digits) -def rankine_to_celsius(rankine: float) -> float: +def rankine_to_celsius(rankine: float, digits: int = 2) -> float: """ Convert a given value from Rankine to Celsius and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale @@ -220,10 +220,10 @@ def rankine_to_celsius(rankine: float) -> float: ... ValueError: could not convert string to float: 'rankine' """ - return round((float(rankine) - 491.67) * 5 / 9, 2) + return round((float(rankine) - 491.67) * 5 / 9, digits) -def rankine_to_fahrenheit(rankine: float) -> float: +def rankine_to_fahrenheit(rankine: float, digits: int = 2) -> float: """ Convert a given value from Rankine to Fahrenheit and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale @@ -240,10 +240,10 @@ def rankine_to_fahrenheit(rankine: float) -> float: ... ValueError: could not convert string to float: 'rankine' """ - return round(float(rankine) - 459.67, 2) + return round(float(rankine) - 459.67, digits) -def rankine_to_kelvin(rankine: float) -> float: +def rankine_to_kelvin(rankine: float, digits: int = 2) -> float: """ Convert a given value from Rankine to Kelvin and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale @@ -260,7 +260,7 @@ def rankine_to_kelvin(rankine: float) -> float: ... ValueError: could not convert string to float: 'rankine' """ - return round((float(rankine) * 5 / 9), 2) + return round((float(rankine) * 5 / 9), digits) if __name__ == "__main__": From 551dbfd9c81d386b7787ef7eb6c2873a9a949f43 Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Fri, 24 Jul 2020 13:26:12 -0700 Subject: [PATCH 4/5] fix variable name --- conversions/temperature_conversions.py | 46 +++++++++++++------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/conversions/temperature_conversions.py b/conversions/temperature_conversions.py index abc113eacdba..70b2f9e2bc22 100644 --- a/conversions/temperature_conversions.py +++ b/conversions/temperature_conversions.py @@ -1,7 +1,7 @@ """ Convert between different units of temperature """ -def celsius_to_fahrenheit(celsius: float, digits: int = 2) -> float: +def celsius_to_fahrenheit(celsius: float, ndigits: int = 2) -> float: """ Convert a given value from Celsius to Fahrenheit and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Celsius @@ -22,10 +22,10 @@ def celsius_to_fahrenheit(celsius: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'celsius' """ - return round((float(celsius) * 9 / 5) + 32, digits) + return round((float(celsius) * 9 / 5) + 32, ndigits) -def celsius_to_kelvin(celsius: float, digits: int = 2) -> float: +def celsius_to_kelvin(celsius: float, ndigits: int = 2) -> float: """ Convert a given value from Celsius to Kelvin and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Celsius @@ -42,10 +42,10 @@ def celsius_to_kelvin(celsius: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'celsius' """ - return round(float(celsius) + 273.15, digits) + return round(float(celsius) + 273.15, ndigits) -def celsius_to_rankine(celsius: float, digits: int = 2) -> float: +def celsius_to_rankine(celsius: float, ndigits: int = 2) -> float: """ Convert a given value from Celsius to Rankine and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Celsius @@ -62,10 +62,10 @@ def celsius_to_rankine(celsius: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'celsius' """ - return round((float(celsius) * 9 / 5) + 491.67, digits) + return round((float(celsius) * 9 / 5) + 491.67, ndigits) -def fahrenheit_to_celsius(fahrenheit: float, digits: int = 2) -> float: +def fahrenheit_to_celsius(fahrenheit: float, ndigits: int = 2) -> float: """ Convert a given value from Fahrenheit to Celsius and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit @@ -88,10 +88,10 @@ def fahrenheit_to_celsius(fahrenheit: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'fahrenheit' """ - return round((float(fahrenheit) - 32) * 5 / 9, digits) + return round((float(fahrenheit) - 32) * 5 / 9, ndigits) -def fahrenheit_to_kelvin(fahrenheit: float, digits: int = 2) -> float: +def fahrenheit_to_kelvin(fahrenheit: float, ndigits: int = 2) -> float: """ Convert a given value from Fahrenheit to Kelvin and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit @@ -114,10 +114,10 @@ def fahrenheit_to_kelvin(fahrenheit: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'fahrenheit' """ - return round(((float(fahrenheit) - 32) * 5 / 9) + 273.15, digits) + return round(((float(fahrenheit) - 32) * 5 / 9) + 273.15, ndigits) -def fahrenheit_to_rankine(fahrenheit: float, digits: int = 2) -> float: +def fahrenheit_to_rankine(fahrenheit: float, ndigits: int = 2) -> float: """ Convert a given value from Fahrenheit to Rankine and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit @@ -140,7 +140,7 @@ def fahrenheit_to_rankine(fahrenheit: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'fahrenheit' """ - return round(float(fahrenheit) + 459.67, digits) + return round(float(fahrenheit) + 459.67, ndigits) def kelvin_to_celsius(kelvin: float, digits: int = 2) -> float: @@ -160,10 +160,10 @@ def kelvin_to_celsius(kelvin: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'kelvin' """ - return round(float(kelvin) - 273.15, digits) + return round(float(kelvin) - 273.15, ndigits) -def kelvin_to_fahrenheit(kelvin: float, digits: int = 2) -> float: +def kelvin_to_fahrenheit(kelvin: float, ndigits: int = 2) -> float: """ Convert a given value from Kelvin to Fahrenheit and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin @@ -180,10 +180,10 @@ def kelvin_to_fahrenheit(kelvin: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'kelvin' """ - return round(((float(kelvin) - 273.15) * 9 / 5) + 32, digits) + return round(((float(kelvin) - 273.15) * 9 / 5) + 32, ndigits) -def kelvin_to_rankine(kelvin: float, digits: int = 2) -> float: +def kelvin_to_rankine(kelvin: float, ndigits: int = 2) -> float: """ Convert a given value from Kelvin to Rankine and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin @@ -200,10 +200,10 @@ def kelvin_to_rankine(kelvin: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'kelvin' """ - return round((float(kelvin) * 9 / 5), digits) + return round((float(kelvin) * 9 / 5), ndigits) -def rankine_to_celsius(rankine: float, digits: int = 2) -> float: +def rankine_to_celsius(rankine: float, ndigits: int = 2) -> float: """ Convert a given value from Rankine to Celsius and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale @@ -220,10 +220,10 @@ def rankine_to_celsius(rankine: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'rankine' """ - return round((float(rankine) - 491.67) * 5 / 9, digits) + return round((float(rankine) - 491.67) * 5 / 9, ndigits) -def rankine_to_fahrenheit(rankine: float, digits: int = 2) -> float: +def rankine_to_fahrenheit(rankine: float, ndigits: int = 2) -> float: """ Convert a given value from Rankine to Fahrenheit and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale @@ -240,10 +240,10 @@ def rankine_to_fahrenheit(rankine: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'rankine' """ - return round(float(rankine) - 459.67, digits) + return round(float(rankine) - 459.67, ndigits) -def rankine_to_kelvin(rankine: float, digits: int = 2) -> float: +def rankine_to_kelvin(rankine: float, ndigits: int = 2) -> float: """ Convert a given value from Rankine to Kelvin and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale @@ -260,7 +260,7 @@ def rankine_to_kelvin(rankine: float, digits: int = 2) -> float: ... ValueError: could not convert string to float: 'rankine' """ - return round((float(rankine) * 5 / 9), digits) + return round((float(rankine) * 5 / 9), ndigits) if __name__ == "__main__": From c8cdb4006dd27ab328ee34b28851581f25d4a3d6 Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Fri, 24 Jul 2020 13:31:26 -0700 Subject: [PATCH 5/5] fixed variable name; helps to stage before commiting --- conversions/temperature_conversions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/temperature_conversions.py b/conversions/temperature_conversions.py index 70b2f9e2bc22..0a8a5ddb6d2c 100644 --- a/conversions/temperature_conversions.py +++ b/conversions/temperature_conversions.py @@ -143,7 +143,7 @@ def fahrenheit_to_rankine(fahrenheit: float, ndigits: int = 2) -> float: return round(float(fahrenheit) + 459.67, ndigits) -def kelvin_to_celsius(kelvin: float, digits: int = 2) -> float: +def kelvin_to_celsius(kelvin: float, ndigits: int = 2) -> float: """ Convert a given value from Kelvin to Celsius and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin