Skip to content

Instantly share code, notes, and snippets.

@xiantail
Created December 28, 2015 13:37
Show Gist options
  • Save xiantail/97074abd649648d8b667 to your computer and use it in GitHub Desktop.
Save xiantail/97074abd649648d8b667 to your computer and use it in GitHub Desktop.
Introducing Python / Chapter 12
F_BOIL_TEMP = 212.0
F_FREEZE_TEMP = 32.0
C_BOIL_TEMP = 100.0
C_FREEZE_TEMP = 0.0
F_RANGE = F_BOIL_TEMP - F_FREEZE_TEMP
C_RANGE = C_BOIL_TEMP - C_FREEZE_TEMP
F_C_RATIO = C_RANGE / F_RANGE
def ftoc(f_temp):
"Convfert Fahrenheit temprature<f_temp> into Celsius "
c_temp = (f_temp - F_FREEZE_TEMP) * F_C_RATIO + C_FREEZE_TEMP
return c_temp
if __name__ == '__main__':
for f_temp in [-40.0, 0.0, 32.0, 100.0, 212.0]:
c_temp = ftoc(f_temp)
print('%f F => %f C' % (f_temp, c_temp))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment