LPTHW Exercise 11-12: Asking Questions, Prompting People

Learn Python the Hard Way by Zed Shaw .: Now we're cooking! Put raw_input() and format() to work:

f = raw_input('What is the temperature today in Clearwater, Florida in Fahrenheit? > ')
c = (float(f) - 32) * (5.0/9)
k = (float(f) - 32) * (5.0/9) + 273.15

print('So a temperature of {} Fahrenheit converts to {:.2f} Celsius and {:.2f} Kelvin.').format(f, c, k)
print('Or, to be more precise, a temperature of {} Fahrenheit converts to {} Celsius and {} Kelvin.').format(f, round(c,5), round(k,5))

Output:

$ python e11.1.py
What is the temperature today in Clearwater, Florida in Fahrenheit? > 80
So a temperature of 80 Fahrenheit converts to 26.67 Celsius and 299.82 Kelvin.
Or, to be more precise, a temperature of 80 Fahrenheit converts to 26.66667 Celsius and 299.81667 Kelvin.
$

More • pythonprogramming