-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Celsius to Fahrenheit Conversions #2188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cclauss
merged 15 commits into
TheAlgorithms:master
from
karimzakir02:celsius_to_fahrenheit
Jul 15, 2020
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1fb92e7
added conversions between celsius and fahrenheit
karimzakir02 e403c20
Renamed celsius_to_fahrenheit.py
karimzakir02 149604d
Fixed spelling issues
karimzakir02 d966cd3
modified file to fit the 88-character limit
karimzakir02 f6a119c
added changes to pass the travis-ci test
karimzakir02 7246685
further changed the files to pass the travis-ci test
karimzakir02 6bf3dca
further changed the files to pass the travis-ci test
karimzakir02 ff16a89
Shortened conversions/fahrenheit_to_celsius.py
karimzakir02 abfa0d5
Type hints added to conversions/fahrenheit_to_celsius.py
karimzakir02 e1673ef
changed the code to let the caller do the printing
karimzakir02 9fdf6ad
Merge branch 'celsius_to_fahrenheit' of https://github.com/karimzakir…
karimzakir02 e8ee42d
addressed the changes made on github
karimzakir02 d239947
Added Kelvin conversions and put temperature functions in a single file
karimzakir02 2715614
Removed whitespace from a blank line
karimzakir02 86eeead
Update temperature_conversions.py
cclauss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" Convert temperature from Celsius to Fahrenheit """ | ||
|
||
|
||
def celsius_to_fahrenheit(celsius: float) -> float: | ||
""" | ||
Convert a given value from Celsius to Fahrenheit and round it to 2 decimal places. | ||
|
||
>>> print(celsius_to_fahrenheit(-40)) | ||
-40.0 | ||
>>> print(celsius_to_fahrenheit(-20)) | ||
-4.0 | ||
>>> print(celsius_to_fahrenheit(0)) | ||
32.0 | ||
>>> print(celsius_to_fahrenheit(20)) | ||
68.0 | ||
>>> print(celsius_to_fahrenheit(40)) | ||
karimzakir02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
104.0 | ||
>>> print(celsius_to_fahrenheit("celsius")) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: could not convert string to float: 'celsius' | ||
""" | ||
|
||
celsius = float(celsius) | ||
return round((celsius * 9 / 5) + 32, 2) | ||
karimzakir02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
doctest.testmod() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" Convert temperature from Fahrenheit to Celsius """ | ||
|
||
|
||
def fahrenheit_to_celsius(fahrenheit: float) -> float: | ||
""" | ||
Convert a given value from Fahrenheit to Celsius and round it to 2 decimal places. | ||
|
||
>>> print(fahrenheit_to_celsius(0)) | ||
-17.78 | ||
>>> print(fahrenheit_to_celsius(20)) | ||
-6.67 | ||
>>> print(fahrenheit_to_celsius(40)) | ||
4.44 | ||
>>> print(fahrenheit_to_celsius(60)) | ||
15.56 | ||
>>> print(fahrenheit_to_celsius(80)) | ||
26.67 | ||
>>> print(fahrenheit_to_celsius(100)) | ||
37.78 | ||
>>> print(fahrenheit_to_celsius("fahrenheit")) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: could not convert string to float: 'fahrenheit' | ||
""" | ||
fahrenheit = float(fahrenheit) | ||
return round((fahrenheit - 32) * 5 / 9, 2) | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
doctest.testmod() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.